Răsfoiți Sursa

Python/Django: Upgrade Django 1.9 to 1.11 (#3067)

* Upgrade all requirements.txt
* Move templates into world app so we don't have to define path
* update urls.py
Ciaran Courtney 7 ani în urmă
părinte
comite
5bc429ea92

+ 1 - 0
frameworks/Python/django/.gitignore

@@ -0,0 +1 @@
+*.sqlite

+ 11 - 14
frameworks/Python/django/hello/hello/settings.py

@@ -3,7 +3,7 @@
 import os
 
 DEBUG = False
-TEMPLATE_DEBUG = DEBUG
+
 
 ADMINS = (
     # ('Your Name', '[email protected]'),
@@ -86,13 +86,6 @@ STATICFILES_FINDERS = (
 # Make this unique, and don't share it with anybody.
 SECRET_KEY = '_7mb6#v4yf@qhc(r(zbyh&z_iby-na*7wz&-v6pohsul-d#y5f'
 
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
-    ('django.template.loaders.cached.Loader', (
-        'django.template.loaders.filesystem.Loader',
-        'django.template.loaders.app_directories.Loader',
-    )),
-)
 
 MIDDLEWARE_CLASSES = (
     'django.middleware.common.CommonMiddleware',
@@ -107,12 +100,16 @@ ROOT_URLCONF = 'hello.urls'
 # Python dotted path to the WSGI application used by Django's runserver.
 WSGI_APPLICATION = 'hello.wsgi.application'
 
-TEMPLATE_DIRS = (
-    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
-    # Always use forward slashes, even on Windows.
-    # Don't forget to use absolute paths, not relative paths.
-    os.path.expandvars("$TROOT/hello/templates"),
-)
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+        },
+    },
+]
 
 INSTALLED_APPS = (
     'django.contrib.auth',

+ 11 - 9
frameworks/Python/django/hello/hello/urls.py

@@ -1,10 +1,12 @@
-from django.conf.urls import patterns, include, url
+from django.conf.urls import url
+
+from world.views import plaintext, json, db, dbs, fortunes, update
 
 # Uncomment the next two lines to enable the admin:
 # from django.contrib import admin
 # admin.autodiscover()
 
-urlpatterns = patterns('',
+urlpatterns = [
     # Examples:
     # url(r'^$', 'hello.views.home', name='home'),
     # url(r'^hello/', include('hello.foo.urls')),
@@ -14,10 +16,10 @@ urlpatterns = patterns('',
 
     # Uncomment the next line to enable the admin:
     # url(r'^admin/', include(admin.site.urls)),
-    url(r'^plaintext$', 'world.views.plaintext'),
-    url(r'^json$', 'world.views.json'),
-    url(r'^db$', 'world.views.db'),
-    url(r'^dbs$', 'world.views.dbs'),
-    url(r'^fortunes$', 'world.views.fortunes'),
-    url(r'^update$', 'world.views.update'),
-)
+    url(r'^plaintext$', plaintext),
+    url(r'^json$', json),
+    url(r'^db$', db),
+    url(r'^dbs$', dbs),
+    url(r'^fortunes$', fortunes),
+    url(r'^update$', update),
+]

+ 0 - 0
frameworks/Python/django/hello/templates/base.html → frameworks/Python/django/hello/world/templates/base.html


+ 0 - 0
frameworks/Python/django/hello/templates/fortunes.html → frameworks/Python/django/hello/world/templates/fortunes.html


+ 7 - 8
frameworks/Python/django/hello/world/views.py

@@ -1,15 +1,14 @@
-# Create your views here.
-
-from django.template import Context, loader
-from django.http import HttpResponse
-from django.core import serializers
-from world.models import World, Fortune
-from django.shortcuts import render
-from ujson import dumps as uj_dumps
 import random
 import sys
 from operator import attrgetter
 from functools import partial
+from ujson import dumps as uj_dumps
+
+from django.http import HttpResponse
+from django.shortcuts import render
+
+from world.models import World, Fortune
+
 
 if sys.version_info[0] == 3:
   xrange = range

+ 7 - 9
frameworks/Python/django/requirements.txt

@@ -1,10 +1,8 @@
-Django==1.9.4
-
-mysqlclient==1.3.7
-psycopg2==2.6.1
-ujson==1.35
-
-gunicorn==19.4.5
+Django==1.11.7
+greenlet==0.4.12
+gunicorn==19.7.1
 meinheld==0.6.1
-
-greenlet==0.4.9
+mysqlclient==1.3.12
+psycopg2==2.7.3.2
+pytz==2017.3
+ujson==1.35