Skip to content

Commit f699fb1

Browse files
author
Chad Smith
committed
update to Django 1.10 and DRF 3.5.3
1 parent 2a56705 commit f699fb1

File tree

6 files changed

+140
-187
lines changed

6 files changed

+140
-187
lines changed

manage.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44

55
if __name__ == "__main__":
66
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tutorial.settings")
7-
8-
from django.core.management import execute_from_command_line
9-
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
1022
execute_from_command_line(sys.argv)

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
djangorestframework==3.3.1
2-
Django==1.8.5
1+
djangorestframework==3.5.3
2+
Django==1.10.2
33
Pygments==2.0.2
44
Markdown==2.6.3
55

snippets/serializers.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tutorial/settings.py

Lines changed: 98 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,128 @@
1-
# Django settings for tutorial project.
1+
"""
2+
Django settings for tutorial project.
23
3-
DEBUG = True
4-
TEMPLATE_DEBUG = DEBUG
4+
Generated by 'django-admin startproject' using Django 1.10.2.
55
6-
ADMINS = (
7-
# ('Your Name', '[email protected]'),
8-
)
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.10/topics/settings/
98
10-
MANAGERS = ADMINS
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.10/ref/settings/
11+
"""
1112

12-
DATABASES = {
13-
'default': {
14-
'ENGINE': 'django.db.backends.sqlite3', # Or use an alternate database backend.
15-
'NAME': 'tmp.db', # Path to sqlite3 database file.
16-
'USER': '', # Not used with sqlite3.
17-
'PASSWORD': '', # Not used with sqlite3.
18-
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
19-
'PORT': '', # Set to empty string for default. Not used with sqlite3.
20-
}
21-
}
13+
import os
2214

23-
# Local time zone for this installation. Choices can be found here:
24-
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
25-
# although not all choices may be available on all operating systems.
26-
# In a Windows environment this must be set to your system time zone.
27-
TIME_ZONE = 'America/Chicago'
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2817

29-
# Language code for this installation. All choices can be found here:
30-
# http://www.i18nguy.com/unicode/language-identifiers.html
31-
LANGUAGE_CODE = 'en-us'
3218

33-
SITE_ID = 1
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
3421

35-
# If you set this to False, Django will make some optimizations so as not
36-
# to load the internationalization machinery.
37-
USE_I18N = True
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'us%!@&39o250e79)l!4*0ac4oquo+^nm83vp#y%mw9i$7)i&fy'
3824

39-
# If you set this to False, Django will not format dates, numbers and
40-
# calendars according to the current locale.
41-
USE_L10N = True
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
4227

43-
# If you set this to False, Django will not use timezone-aware datetimes.
44-
USE_TZ = True
28+
ALLOWED_HOSTS = []
4529

46-
# Absolute filesystem path to the directory that will hold user-uploaded files.
47-
# Example: "/home/media/media.lawrence.com/media/"
48-
MEDIA_ROOT = ''
4930

50-
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
51-
# trailing slash.
52-
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
53-
MEDIA_URL = ''
31+
# Application definition
5432

55-
# Absolute path to the directory static files should be collected to.
56-
# Don't put anything in this directory yourself; store your static files
57-
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
58-
# Example: "/home/media/media.lawrence.com/static/"
59-
STATIC_ROOT = ''
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'rest_framework',
41+
]
6042

61-
# URL prefix for static files.
62-
# Example: "http://media.lawrence.com/static/"
63-
STATIC_URL = '/static/'
43+
REST_FRAMEWORK = {
44+
'DEFAULT_PERMISSION_CLASSES': [
45+
'rest_framework.permissions.IsAdminUser',
46+
],
47+
'PAGE_SIZE': 10
48+
}
6449

65-
# Additional locations of static files
66-
STATICFILES_DIRS = (
67-
# Put strings here, like "/home/html/static" or "C:/www/django/static".
68-
# Always use forward slashes, even on Windows.
69-
# Don't forget to use absolute paths, not relative paths.
70-
)
71-
72-
# List of finder classes that know how to find static files in
73-
# various locations.
74-
STATICFILES_FINDERS = (
75-
'django.contrib.staticfiles.finders.FileSystemFinder',
76-
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
77-
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
78-
)
79-
80-
# Make this unique, and don't share it with anybody.
81-
SECRET_KEY = '98s9du5ruv!j%shx0udb#uz1g@v^xl65zm1l-_5%8cs6%c*qm$'
82-
83-
# List of callables that know how to import templates from various sources.
84-
TEMPLATE_LOADERS = (
85-
'django.template.loaders.filesystem.Loader',
86-
'django.template.loaders.app_directories.Loader',
87-
# 'django.template.loaders.eggs.Loader',
88-
)
89-
90-
MIDDLEWARE_CLASSES = (
91-
'django.middleware.common.CommonMiddleware',
50+
MIDDLEWARE = [
51+
'django.middleware.security.SecurityMiddleware',
9252
'django.contrib.sessions.middleware.SessionMiddleware',
53+
'django.middleware.common.CommonMiddleware',
9354
'django.middleware.csrf.CsrfViewMiddleware',
9455
'django.contrib.auth.middleware.AuthenticationMiddleware',
9556
'django.contrib.messages.middleware.MessageMiddleware',
96-
# Uncomment the next line for simple clickjacking protection:
97-
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
98-
)
57+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
58+
]
9959

10060
ROOT_URLCONF = 'tutorial.urls'
10161

102-
# Python dotted path to the WSGI application used by Django's runserver.
62+
TEMPLATES = [
63+
{
64+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
65+
'DIRS': [],
66+
'APP_DIRS': True,
67+
'OPTIONS': {
68+
'context_processors': [
69+
'django.template.context_processors.debug',
70+
'django.template.context_processors.request',
71+
'django.contrib.auth.context_processors.auth',
72+
'django.contrib.messages.context_processors.messages',
73+
],
74+
},
75+
},
76+
]
77+
10378
WSGI_APPLICATION = 'tutorial.wsgi.application'
10479

105-
TEMPLATE_DIRS = (
106-
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
107-
# Always use forward slashes, even on Windows.
108-
# Don't forget to use absolute paths, not relative paths.
109-
)
11080

111-
INSTALLED_APPS = (
112-
'django.contrib.auth',
113-
'django.contrib.contenttypes',
114-
'django.contrib.sessions',
115-
'django.contrib.sites',
116-
'django.contrib.messages',
117-
'django.contrib.staticfiles',
118-
# Uncomment the next line to enable the admin:
119-
# 'django.contrib.admin',
120-
# Uncomment the next line to enable admin documentation:
121-
# 'django.contrib.admindocs',
122-
'rest_framework',
123-
'snippets',
124-
)
125-
126-
# A sample logging configuration. The only tangible logging
127-
# performed by this configuration is to send an email to
128-
# the site admins on every HTTP 500 error when DEBUG=False.
129-
# See http://docs.djangoproject.com/en/dev/topics/logging for
130-
# more details on how to customize your logging configuration.
131-
LOGGING = {
132-
'version': 1,
133-
'disable_existing_loggers': False,
134-
'filters': {
135-
'require_debug_false': {
136-
'()': 'django.utils.log.RequireDebugFalse'
137-
}
138-
},
139-
'handlers': {
140-
'mail_admins': {
141-
'level': 'ERROR',
142-
'filters': ['require_debug_false'],
143-
'class': 'django.utils.log.AdminEmailHandler'
144-
}
145-
},
146-
'loggers': {
147-
'django.request': {
148-
'handlers': ['mail_admins'],
149-
'level': 'ERROR',
150-
'propagate': True,
151-
},
81+
# Database
82+
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
83+
84+
DATABASES = {
85+
'default': {
86+
'ENGINE': 'django.db.backends.sqlite3',
87+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
15288
}
15389
}
15490

155-
REST_FRAMEWORK = {
156-
'PAGE_SIZE': 10,
157-
}
15891

159-
import os
160-
if os.environ.get('HEROKU'): # heroku config:set HEROKU=1
161-
import dj_database_url
162-
DATABASES['default'] = dj_database_url.config()
92+
# Password validation
93+
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
94+
95+
AUTH_PASSWORD_VALIDATORS = [
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
101+
},
102+
{
103+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
104+
},
105+
{
106+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
107+
},
108+
]
163109

164-
LOGIN_REDIRECT_URL = '/'
110+
111+
# Internationalization
112+
# https://docs.djangoproject.com/en/1.10/topics/i18n/
113+
114+
LANGUAGE_CODE = 'en-us'
115+
116+
TIME_ZONE = 'UTC'
117+
118+
USE_I18N = True
119+
120+
USE_L10N = True
121+
122+
USE_TZ = True
123+
124+
125+
# Static files (CSS, JavaScript, Images)
126+
# https://docs.djangoproject.com/en/1.10/howto/static-files/
127+
128+
STATIC_URL = '/static/'

tutorial/urls.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
from snippets import views
2-
from django.conf.urls import patterns, url, include
3-
from rest_framework.routers import DefaultRouter
1+
"""tutorial URL Configuration
42
5-
router = DefaultRouter()
6-
router.register(r'snippets', views.SnippetViewSet)
7-
router.register(r'users', views.UserViewSet)
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/1.10/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.conf.urls import url, include
14+
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import url
17+
from django.contrib import admin
818

9-
urlpatterns = patterns('',
10-
url(r'^', include(router.urls)),
11-
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
12-
)
19+
urlpatterns = [
20+
url(r'^admin/', admin.site.urls),
21+
]

tutorial/wsgi.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
"""
22
WSGI config for tutorial project.
33
4-
This module contains the WSGI application used by Django's development server
5-
and any production WSGI deployments. It should expose a module-level variable
6-
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7-
this application via the ``WSGI_APPLICATION`` setting.
8-
9-
Usually you will have the standard Django WSGI application here, but it also
10-
might make sense to replace the whole Django WSGI application with a custom one
11-
that later delegates to the Django one. For example, you could introduce WSGI
12-
middleware here, or combine a Django application with an application of another
13-
framework.
4+
It exposes the WSGI callable as a module-level variable named ``application``.
145
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
158
"""
9+
1610
import os
1711

12+
from django.core.wsgi import get_wsgi_application
13+
1814
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tutorial.settings")
1915

20-
# This application object is used by any WSGI server configured to use this
21-
# file. This includes Django's development server, if the WSGI_APPLICATION
22-
# setting points here.
23-
from django.core.wsgi import get_wsgi_application
2416
application = get_wsgi_application()
25-
26-
# Apply WSGI middleware here.
27-
# from helloworld.wsgi import HelloWorldApplication
28-
# application = HelloWorldApplication(application)

0 commit comments

Comments
 (0)