diff --git a/starter/manage.py b/starter/manage.py index 2bd100b..b0464d4 100755 --- a/starter/manage.py +++ b/starter/manage.py @@ -1,27 +1,13 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" + import os import sys - -def main(): - """Run administrative tasks.""" +if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "starter.settings") os.environ.setdefault("DJANGO_CONFIGURATION", "Production") - try: - # Install django-configurations importer - from configurations.importer import install - install(check_options=True) - from django.core.management import execute_from_command_line - except ImportError as exc: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) from exc - execute_from_command_line(sys.argv) + from configurations.management import execute_from_command_line - -if __name__ == "__main__": - main() + execute_from_command_line(sys.argv) diff --git a/starter/starter/asgi.py b/starter/starter/asgi.py index 39563b6..57223e3 100644 --- a/starter/starter/asgi.py +++ b/starter/starter/asgi.py @@ -8,15 +8,11 @@ """ import os - -# Install django-configurations importer -from configurations.importer import install - -install(check_options=True) - -from django.core.asgi import get_asgi_application +import sys os.environ.setdefault("DJANGO_SETTINGS_MODULE", "starter.settings") os.environ.setdefault("DJANGO_CONFIGURATION", "Production") -application = get_asgi_application() +from configurations.management import execute_from_command_line + +execute_from_command_line(sys.argv) diff --git a/starter/starter/settings.py b/starter/starter/settings.py index d1057c0..a4c750a 100644 --- a/starter/starter/settings.py +++ b/starter/starter/settings.py @@ -1,13 +1,13 @@ """ Django settings for starter project. -Generated by 'django-admin startproject' using Django 3.2.5. +Generated by 'django-admin startproject' using Django 5.1.3. For more information on this file, see -https://docs.djangoproject.com/en/3.2/topics/settings/ +https://docs.djangoproject.com/en/5.1/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/3.2/ref/settings/ +https://docs.djangoproject.com/en/5.1/ref/settings/ """ from pathlib import Path @@ -63,7 +63,7 @@ class Common(Configuration): WSGI_APPLICATION = "starter.wsgi.application" # Password validation - # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + # https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -81,7 +81,7 @@ class Common(Configuration): ] # Internationalization - # https://docs.djangoproject.com/en/3.2/topics/i18n/ + # https://docs.djangoproject.com/en/5.1/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -94,27 +94,22 @@ class Common(Configuration): USE_TZ = True # Static files (CSS, JavaScript, Images) - # https://docs.djangoproject.com/en/3.2/howto/static-files/ + # https://docs.djangoproject.com/en/5.1/howto/static-files/ STATIC_URL = values.Value("/static", environ_name="DBMI_APP_STATIC_URL_PATH") + "/" STATIC_ROOT = values.Value("/var/static", environ_name="DBMI_APP_STATIC_ROOT") # Default primary key field type - # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + # https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" - # Set a test runner to hand test runs off to pytest - # https://docs.djangoproject.com/en/3.2/ref/settings/#test-runner - - TEST_RUNNER = "tests.runner.PytestTestRunner" - class Production(Common): """This is the production site settings configuration.""" # Quick-start development settings - unsuitable for production - # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = values.SecretValue(environ_prefix="", environ_required=True) @@ -123,19 +118,49 @@ class Production(Common): DEBUG = False # Allowed Hosts - # https://docs.djangoproject.com/en/3.2/ref/settings/#allowed-hosts + # https://docs.djangoproject.com/en/5.1/ref/settings/#allowed-hosts ALLOWED_HOSTS = values.ListValue(environ_prefix="", environ_required=True) # Database - # https://docs.djangoproject.com/en/3.2/ref/settings/#databases + # https://docs.djangoproject.com/en/5.1/ref/settings/#databases + DATABASES = { + "default": { + "ENGINE": values.Value(environ_prefix="DB", environ_name="ENGINE", environ_required=True), + "NAME": values.Value(environ_prefix="DB", environ_name="NAME", environ_required=True), + "USER": values.Value(environ_prefix="DB", environ_name="USER", environ_required=True), + "PASSWORD": values.Value(environ_prefix="DB", environ_name="PASSWORD", environ_required=True), + "HOST": values.Value(environ_prefix="DB", environ_name="HOST", environ_required=True), + "PORT": values.Value(environ_prefix="DB", environ_name="PORT", environ_required=True), + } + } + + +class Development(Common): + """This is the settings configuration to use for development.""" + + # Quick-start development settings - unsuitable for production + # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ + + # SECURITY WARNING: keep the secret key used in production secret! + SECRET_KEY = "thisisasecretkeythatisnotusedinanyactualenvironment" + + # SECURITY WARNING: don't run with debug turned on in production! + DEBUG = True + + # Allowed Hosts + # https://docs.djangoproject.com/en/5.1/ref/settings/#allowed-hosts + ALLOWED_HOSTS = ["*"] + + # Database + # https://docs.djangoproject.com/en/5.1/ref/settings/#databases DATABASES = { "default": { - "ENGINE": values.Value(environ_prefix="DB", environ_required=True), - "NAME": values.Value(environ_prefix="DB", environ_required=True), - "USER": values.Value(environ_prefix="DB", environ_required=True), - "PASSWORD": values.Value(environ_prefix="DB", environ_required=True), - "HOST": values.Value(environ_prefix="DB", environ_required=True), - "PORT": values.Value(environ_prefix="DB", environ_required=True), + "ENGINE": values.Value(environ_prefix="DB", environ_name="ENGINE", environ_required=True), + "NAME": values.Value(environ_prefix="DB", environ_name="NAME", environ_required=True), + "USER": values.Value(environ_prefix="DB", environ_name="USER", environ_required=True), + "PASSWORD": values.Value(environ_prefix="DB", environ_name="PASSWORD", environ_required=True), + "HOST": values.Value(environ_prefix="DB", environ_name="HOST", environ_required=True), + "PORT": values.Value(environ_prefix="DB", environ_name="PORT", environ_required=True), } } @@ -144,7 +169,7 @@ class Test(Common): """This is the settings configuration to use for testing.""" # Quick-start development settings - unsuitable for production - # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "thisisasecretkeythatisnotusedinanyactualenvironment" @@ -153,11 +178,11 @@ class Test(Common): DEBUG = True # Allowed Hosts - # https://docs.djangoproject.com/en/3.2/ref/settings/#allowed-hosts + # https://docs.djangoproject.com/en/5.1/ref/settings/#allowed-hosts ALLOWED_HOSTS = ["*"] # Database - # https://docs.djangoproject.com/en/3.2/ref/settings/#databases + # https://docs.djangoproject.com/en/5.1/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", diff --git a/starter/starter/wsgi.py b/starter/starter/wsgi.py index fa1466f..058ef1d 100644 --- a/starter/starter/wsgi.py +++ b/starter/starter/wsgi.py @@ -9,14 +9,9 @@ import os -# Install django-configurations importer -from configurations.importer import install - -install(check_options=True) - -from django.core.wsgi import get_wsgi_application - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "starter.settings") os.environ.setdefault("DJANGO_CONFIGURATION", "Production") +from configurations.wsgi import get_wsgi_application + application = get_wsgi_application()