diff --git a/.gitignore b/.gitignore index 67c1de1..f7f3285 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ venv/* .idea/* db.sqlite3 +*__pycache__* +.env diff --git a/gmba_django/settings/Pipfile b/gmba_django/settings/Pipfile new file mode 100644 index 0000000..7a9e19a --- /dev/null +++ b/gmba_django/settings/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.6" diff --git a/gmba_django/settings.py b/gmba_django/settings/base.py similarity index 90% rename from gmba_django/settings.py rename to gmba_django/settings/base.py index 28503bd..ebc1bbf 100644 --- a/gmba_django/settings.py +++ b/gmba_django/settings/base.py @@ -9,23 +9,22 @@ https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ +import os +from django.core.exceptions import ImproperlyConfigured from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-78s5o(bolc72n@8m3^mx6+g@+e^$g4m#vbv(1+467@u^rx96ic' +SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') # Application definition @@ -70,18 +69,6 @@ TEMPLATES = [ WSGI_APPLICATION = 'gmba_django.wsgi.application' - -# Database -# https://docs.djangoproject.com/en/3.2/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': BASE_DIR / 'db.sqlite3', - } -} - - # Password validation # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators diff --git a/gmba_django/settings/development.py b/gmba_django/settings/development.py new file mode 100644 index 0000000..b9114a7 --- /dev/null +++ b/gmba_django/settings/development.py @@ -0,0 +1,10 @@ +from .base import * + +DEBUG = True + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} \ No newline at end of file diff --git a/gmba_django/settings/production.py b/gmba_django/settings/production.py new file mode 100644 index 0000000..3b72011 --- /dev/null +++ b/gmba_django/settings/production.py @@ -0,0 +1,24 @@ +from .base import * + +DEBUG = False + +ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', "").split(",") + +DATABASES = { + 'default': { + 'ENGINE': os.environ.get('SQL_ENGINE', 'django.db.backends.sqlite3'), + 'NAME': os.environ.get('SQL_DATABASE', os.path.join(BASE_DIR, 'db.sqlite3')), + 'USER': os.environ.get('SQL_USER', 'user'), + 'PASSWORD': os.environ.get('SQL_PASSWORD', 'password'), + 'HOST': os.environ.get('SQL_HOST', 'localhost'), + 'PORT': os.environ.get('SQL_PORT', ''), + } +} + +SECURE_SSL_REDIRECT = True + +SESSION_COOKIE_SECURE = True + +CSRF_COOKIE_SECURE = True + +SECURE_BROWSER_XSS_FILTER = True \ No newline at end of file diff --git a/gmba_django/wsgi.py b/gmba_django/wsgi.py index 8b7f44f..a2998c5 100644 --- a/gmba_django/wsgi.py +++ b/gmba_django/wsgi.py @@ -8,9 +8,17 @@ https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """ import os +import dotenv from django.core.wsgi import get_wsgi_application -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gmba_django.settings') +dotenv.load_dotenv( + os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env') +) + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gmba_django.settings.develop') + +if os.getenv('DJANGO_SETTINGS_MODULE'): + os.environ['DJANGO_SETTINGS_MODULE'] = os.getenv('DJANGO_SETTINGS_MODULE') application = get_wsgi_application() diff --git a/manage.py b/manage.py index ea3313f..ebb378e 100755 --- a/manage.py +++ b/manage.py @@ -1,12 +1,18 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" +import dotenv import os import sys + def main(): """Run administrative tasks.""" - os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gmba_django.settings') + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gmba_django.settings.development') + + if os.getenv('DJANGO_SETTINGS_MODULE'): + os.environ['DJANGO_SETTINGS_MODULE'] = os.getenv('DJANGO_SETTINGS_MODULE') + try: from django.core.management import execute_from_command_line except ImportError as exc: @@ -20,3 +26,7 @@ def main(): if __name__ == '__main__': main() + +dotenv.load_dotenv( + os.path.join(os.path.dirname(__file__), '.env') +) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..53c22db --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +asgiref==3.4.1 +Django==3.2.5 +python-dotenv==0.19.0 +pytz==2021.1 +sqlparse==0.4.1 +typing-extensions==3.10.0.0