From 2bf20b05290d0601d5a01d6d3b1d959a16596b5b Mon Sep 17 00:00:00 2001 From: Dimitri Prosper Date: Sat, 11 Dec 2021 00:02:00 -0500 Subject: [PATCH] updated to django 4.0 --- app/asgi.py | 16 ++++++++++++++++ app/settings.py | 43 ++++++++++++++++++++++--------------------- app/urls.py | 12 ++++++------ app/wsgi.py | 4 ++-- manage.py | 30 +++++++++++++++--------------- 5 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 app/asgi.py diff --git a/app/asgi.py b/app/asgi.py new file mode 100644 index 0000000..3163a3a --- /dev/null +++ b/app/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for app project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') + +application = get_asgi_application() diff --git a/app/settings.py b/app/settings.py index 6a21353..18250bc 100644 --- a/app/settings.py +++ b/app/settings.py @@ -1,31 +1,31 @@ """ Django settings for app project. -Generated by 'django-admin startproject' using Django 1.11.8. +Generated by 'django-admin startproject' using Django 4.0. For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ +https://docs.djangoproject.com/en/4.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.11/ref/settings/ +https://docs.djangoproject.com/en/4.0/ref/settings/ """ -import os +from pathlib import Path -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# 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/1.11/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'v67+e8%==!6$h14iv^30axxwozum45vlj+9)m2$2iq#*^agn6+' +SECRET_KEY = 'django-insecure-a4wjq&5q%rmgzzzrhzau7ac@3^hl6!0=_vl!h5#@4)ivi5stpv' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = ['*'] +ALLOWED_HOSTS = [] # Application definition @@ -36,7 +36,7 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - # 'django.contrib.staticfiles', + 'django.contrib.staticfiles', ] MIDDLEWARE = [ @@ -54,9 +54,7 @@ TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - os.path.join(os.path.dirname(__file__), 'templates'), - ], + 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -73,18 +71,18 @@ # Database -# https://docs.djangoproject.com/en/1.11/ref/settings/#databases +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': BASE_DIR / 'db.sqlite3', } } # Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -103,7 +101,7 @@ # Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ +# https://docs.djangoproject.com/en/4.0/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -111,12 +109,15 @@ USE_I18N = True -USE_L10N = True - USE_TZ = True # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field -STATIC_URL = '/static/' +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/app/urls.py b/app/urls.py index 06cd68f..348c5f1 100644 --- a/app/urls.py +++ b/app/urls.py @@ -1,17 +1,17 @@ -"""mysite URL Configuration +"""app URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/1.11/topics/http/urls/ + https://docs.djangoproject.com/en/4.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') + 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf - 1. Import the include() function: from django.conf.urls import url, include - 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import re_path from django.contrib import admin diff --git a/app/wsgi.py b/app/wsgi.py index cefd1ed..e1bcdb1 100644 --- a/app/wsgi.py +++ b/app/wsgi.py @@ -1,10 +1,10 @@ """ -WSGI config for app project. +WSGI config for mysite project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ """ import os diff --git a/manage.py b/manage.py index 2890288..8e7620c 100755 --- a/manage.py +++ b/manage.py @@ -6,24 +6,24 @@ # then are logged. #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" import os import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') try: from django.core.management import execute_from_command_line - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django - except ImportError: - 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?" - ) - raise + 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) + + +if __name__ == '__main__': + main()