From b94dd0b99d47aec58a7f51f6b8d59ac5367478d4 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 21 May 2020 15:58:52 +0200 Subject: [PATCH 1/6] Update of requirements to Django 2.2.12 LTS --- requirements.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 321f32e..b85f91f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,7 @@ -django>=1.11,<1.12 -django-debug-toolbar==1.8 -gunicorn==19.5.0 +Django>=2.2.12,<3.0 +django-debug-toolbar==2.2 +gunicorn==20.0.4 psycopg2==2.8.5 -whitenoise==3.3.1 +pytz==2020.1 +sqlparse==0.3.1 +whitenoise==5.1.0 From 613e50c488315dc74f0a94178f0b68910b39b542 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 21 May 2020 16:24:44 +0200 Subject: [PATCH 2/6] Rebuild of Django project --- manage.py | 19 +++++++++++++++---- project/settings.py | 18 +++++++++--------- project/urls.py | 28 +++++++++++++++++++--------- wsgi.py => project/wsgi.py | 6 +++--- 4 files changed, 46 insertions(+), 25 deletions(-) rename wsgi.py => project/wsgi.py (58%) diff --git a/manage.py b/manage.py index 82cfa83..364337c 100755 --- a/manage.py +++ b/manage.py @@ -1,10 +1,21 @@ #!/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", "project.settings") - - from django.core.management import execute_from_command_line +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') + try: + 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) + + +if __name__ == '__main__': + main() diff --git a/project/settings.py b/project/settings.py index 8855547..9d3186e 100644 --- a/project/settings.py +++ b/project/settings.py @@ -1,13 +1,13 @@ """ Django settings for this project. -Generated by 'django-admin startproject' using Django 1.11.6. +Generated by 'django-admin startproject' using Django 2.2.12. For more information on this file, see -https://docs.djangoproject.com/en/1.11/topics/settings/ +https://docs.djangoproject.com/en/2.2/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/2.2/ref/settings/ """ import os @@ -17,7 +17,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # The SECRET_KEY is provided via an environment variable in OpenShift @@ -76,11 +76,11 @@ TEMPLATES = [ }, ] -WSGI_APPLICATION = 'wsgi.application' +WSGI_APPLICATION = 'project.wsgi.application' # Database -# https://docs.djangoproject.com/en/1.11/ref/settings/#databases +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases from . import database @@ -90,7 +90,7 @@ DATABASES = { # Password validation -# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -109,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization -# https://docs.djangoproject.com/en/1.11/topics/i18n/ +# https://docs.djangoproject.com/en/2.2/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -123,7 +123,7 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.11/howto/static-files/ +# https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') diff --git a/project/urls.py b/project/urls.py index 5c6a8e3..87c399e 100644 --- a/project/urls.py +++ b/project/urls.py @@ -1,17 +1,27 @@ -from django.conf import settings -from django.conf.urls import include, url +"""project URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 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: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" from django.contrib import admin +from django.urls import path from welcome.views import index, health urlpatterns = [ - # Examples: - # url(r'^$', 'project.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - - url(r'^$', index), - url(r'^health$', health), - url(r'^admin/', include(admin.site.urls)), + path('', index, name='home'), + path('health/', health), + path('admin/', admin.site.urls), ] if settings.DEBUG: diff --git a/wsgi.py b/project/wsgi.py similarity index 58% rename from wsgi.py rename to project/wsgi.py index 2ef9a16..88349e8 100644 --- a/wsgi.py +++ b/project/wsgi.py @@ -1,16 +1,16 @@ """ -WSGI config for project project. +WSGI config for this 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/2.2/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') application = get_wsgi_application() From d6a79c94b0253d61daaa4d52863edfc36c101cf6 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 21 May 2020 16:32:42 +0200 Subject: [PATCH 3/6] Recreated app welcome --- welcome/apps.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 welcome/apps.py diff --git a/welcome/apps.py b/welcome/apps.py new file mode 100644 index 0000000..8b57e25 --- /dev/null +++ b/welcome/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class WelcomeConfig(AppConfig): + name = 'welcome' From d13d62ecd7da534f5524f27bd0a6fd02ba06cc66 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 21 May 2020 16:42:31 +0200 Subject: [PATCH 4/6] Fix project settings --- project/urls.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/project/urls.py b/project/urls.py index 87c399e..b631d2d 100644 --- a/project/urls.py +++ b/project/urls.py @@ -13,8 +13,9 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings from django.contrib import admin -from django.urls import path +from django.urls import include, path from welcome.views import index, health @@ -27,5 +28,5 @@ urlpatterns = [ if settings.DEBUG: import debug_toolbar urlpatterns = [ - url(r'^__debug__/', include(debug_toolbar.urls)), + path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns From a8370470e755926d635dc578055524914da30afc Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Mon, 8 Jun 2020 08:09:38 +0200 Subject: [PATCH 5/6] Update readme --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fd515a5..a2860f1 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,7 @@ To run this project in your development machine, follow these steps: 1. (optional) Create and activate a [virtualenv](https://virtualenv.pypa.io/) (you may want to use [virtualenvwrapper](http://virtualenvwrapper.readthedocs.org/)). -2. Ensure that the executable `pg_config` is available on your machine. You can check this using `which pg_config`. If not, install the dependency with one of the following. - - macOS: `brew install postgresql` using [Homebrew](https://brew.sh/) - - Ubuntu: `sudo apt-get install libpq-dev` - - [Others](https://stackoverflow.com/a/12037133/8122577) +2. Ensure that the executable `pg_config` is available on your machine. You can check this using `which pg_config`. Otherwise, sqlite will be used. 3. Fork this repo and clone your fork: @@ -120,8 +117,8 @@ Templates give you full control of each component of your application. Sometimes your application is simple enough and you don't want to bother with templates. In that case, you can let OpenShift inspect your source code and create the required components automatically for you: ```bash -$ oc new-app centos/python-35-centos7~https://github.com/sclorg/django-ex -imageStreams/python-35-centos7 +$ oc new-app centos/python-36-centos7~https://github.com/sclorg/django-ex +imageStreams/python-36-centos7 imageStreams/django-ex buildConfigs/django-ex deploymentConfigs/django-ex From 1ef084115632d0e94a792bc1e601ab0468971ae5 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Thu, 9 Jul 2020 11:21:24 +0200 Subject: [PATCH 6/6] Add a note about older Django version --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a2860f1..1d1c60f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This is a [Django](http://www.djangoproject.com) project that you can use as the starting point to develop your own and deploy it on an [OpenShift](https://github.com/openshift/origin) cluster. +**NOTE:** The current master branch works with Django 2.2 LTS. The version for older Django 1.11 LTS is in [branch 1.11.x](https://github.com/sclorg/django-ex/tree/1.11.x). + The steps in this document assume that you have access to an OpenShift deployment that you can deploy applications on. ## What has been done for you