From 754671747502d6c44dc00614eb0c315cad2d777a Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Mon, 1 Feb 2021 15:19:06 +1100 Subject: [PATCH] Update to latest versions of django and python3.8 --- Dockerfile | 2 +- hello/views.py | 3 +-- manage.py | 9 ++++++++- requirements.txt | 4 ++-- web_project/asgi.py | 16 ++++++++++++++++ web_project/settings.py | 31 ++++++++++++++----------------- web_project/urls.py | 2 +- web_project/wsgi.py | 2 +- 8 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 web_project/asgi.py diff --git a/Dockerfile b/Dockerfile index 655c009..f897986 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Pull a pre-built alpine docker image with nginx and python3 installed -FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7 +FROM tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19 # Set the port on which the app runs; make both values the same. # diff --git a/hello/views.py b/hello/views.py index d3b85af..c098e70 100644 --- a/hello/views.py +++ b/hello/views.py @@ -1,6 +1,5 @@ -from datetime import datetime - from django.shortcuts import redirect, render +from django.utils.timezone import datetime from django.views.generic import ListView from hello.forms import LogMessageForm diff --git a/manage.py b/manage.py index 91d2549..887879a 100644 --- a/manage.py +++ b/manage.py @@ -1,8 +1,11 @@ #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" import os import sys -if __name__ == '__main__': + +def main(): + """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'web_project.settings') try: from django.core.management import execute_from_command_line @@ -13,3 +16,7 @@ "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index c57b511..d9a2845 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Django>=2.1.2 -pytz==2018.5 +Django>=3.1.0 +pytz==2020.5 diff --git a/web_project/asgi.py b/web_project/asgi.py new file mode 100644 index 0000000..d52c19d --- /dev/null +++ b/web_project/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for web_project 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/3.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'web_project.settings') + +application = get_asgi_application() diff --git a/web_project/settings.py b/web_project/settings.py index ffe06de..7d8bc50 100644 --- a/web_project/settings.py +++ b/web_project/settings.py @@ -1,30 +1,27 @@ """ Django settings for web_project project. -Generated by 'django-admin startproject' using Django 2.1.1. +Generated by 'django-admin startproject' using Django 3.1.5. For more information on this file, see -https://docs.djangoproject.com/en/2.1/topics/settings/ +https://docs.djangoproject.com/en/3.1/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.1/ref/settings/ +https://docs.djangoproject.com/en/3.1/ref/settings/ """ -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +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/2.1/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '2gult1d96#@#b2%tz+k9x1q%-4(%f@va-!sbv*q&$t^gpp8-_=' +SECRET_KEY = '6cskd7@vosz+^h5org$_jjq)l$ai-05q8-g^^$tdb$x*ud7e0=' # SECURITY WARNING: don't run with debug turned on in production! -# If you set to False, also add "localhost" to ALLOWED_HOSTS or else -# you'll get "Bad Request" when running locally. DEBUG = True # When deploying to Azure App Service, add you .azurewebsites.net @@ -81,18 +78,18 @@ # Database -# https://docs.djangoproject.com/en/2.1/ref/settings/#databases +# https://docs.djangoproject.com/en/3.1/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/2.1/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -111,7 +108,7 @@ # Internationalization -# https://docs.djangoproject.com/en/2.1/topics/i18n/ +# https://docs.djangoproject.com/en/3.1/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -125,7 +122,7 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.1/howto/static-files/ +# https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' @@ -133,4 +130,4 @@ # A dedicated static file server is typically used in production to serve files # from this location, rather than relying on the app server to serve those files # from various locations in the app. Doing so results in better overall performance. -STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected') +STATIC_ROOT = BASE_DIR / 'static_collected' diff --git a/web_project/urls.py b/web_project/urls.py index 71bcdf9..c4606b2 100644 --- a/web_project/urls.py +++ b/web_project/urls.py @@ -1,7 +1,7 @@ """web_project URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.1/topics/http/urls/ + https://docs.djangoproject.com/en/3.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views diff --git a/web_project/wsgi.py b/web_project/wsgi.py index b8b7e7f..c352092 100644 --- a/web_project/wsgi.py +++ b/web_project/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ """ import os