diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/conf/app_template/admin.py | 3 | ||||
| -rw-r--r-- | django/conf/app_template/tests.py | 15 | ||||
| -rw-r--r-- | django/conf/app_template/views.py | 2 | ||||
| -rw-r--r-- | django/conf/project_template/project_name/settings.py | 178 | ||||
| -rw-r--r-- | django/conf/project_template/project_name/urls.py | 13 | ||||
| -rw-r--r-- | django/conf/project_template/project_name/wsgi.py | 26 | ||||
| -rw-r--r-- | django/core/management/templates.py | 5 | ||||
| -rw-r--r-- | django/views/debug.py | 29 |
8 files changed, 87 insertions, 184 deletions
diff --git a/django/conf/app_template/admin.py b/django/conf/app_template/admin.py new file mode 100644 index 0000000000..8c38f3f3da --- /dev/null +++ b/django/conf/app_template/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django/conf/app_template/tests.py b/django/conf/app_template/tests.py index 501deb776c..7ce503c2dd 100644 --- a/django/conf/app_template/tests.py +++ b/django/conf/app_template/tests.py @@ -1,16 +1,3 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". - -Replace this with more appropriate tests for your application. -""" - from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) +# Create your tests here. diff --git a/django/conf/app_template/views.py b/django/conf/app_template/views.py index 60f00ef0ef..91ea44a218 100644 --- a/django/conf/app_template/views.py +++ b/django/conf/app_template/views.py @@ -1 +1,3 @@ +from django.shortcuts import render + # Create your views here. diff --git a/django/conf/project_template/project_name/settings.py b/django/conf/project_template/project_name/settings.py index 559e27ca16..8815dc6bc0 100644 --- a/django/conf/project_template/project_name/settings.py +++ b/django/conf/project_template/project_name/settings.py @@ -1,152 +1,82 @@ -# Django settings for {{ project_name }} project. +""" +Django settings for {{ project_name }} project. -DEBUG = True -TEMPLATE_DEBUG = DEBUG - -ADMINS = ( - # ('Your Name', 'your_email@example.com'), -) - -MANAGERS = ADMINS - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': '', # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: - 'USER': '', - 'PASSWORD': '', - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. - } -} - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# In a Windows environment this must be set to your system time zone. -TIME_ZONE = 'America/Chicago' - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' - -SITE_ID = 1 - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True +For more information on this file, see +https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/ -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale. -USE_L10N = True +For the full list of settings and their values, see +https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ +""" -# If you set this to False, Django will not use timezone-aware datetimes. -USE_TZ = True +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/var/www/example.com/media/" -MEDIA_ROOT = '' -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://example.com/media/", "http://media.example.com/" -MEDIA_URL = '' +# Quick-start development settings - unsuitable for production -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/var/www/example.com/static/" -STATIC_ROOT = '' +# SECURITY WARNING: keep the secret key used in production secret! +# Hardcoded values can leak through source control. Consider loading +# the secret key from an environment variable or a file instead. +SECRET_KEY = '{{ secret_key }}' -# URL prefix for static files. -# Example: "http://example.com/static/", "http://static.example.com/" -STATIC_URL = '/static/' +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True -# Additional locations of static files -STATICFILES_DIRS = ( - # Put strings here, like "/home/html/static" or "C:/www/django/static". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) +TEMPLATE_DEBUG = True -# List of finder classes that know how to find static files in -# various locations. -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - # 'django.contrib.staticfiles.finders.DefaultStorageFinder', -) -# Make this unique, and don't share it with anybody. -SECRET_KEY = '{{ secret_key }}' +# Application definition -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - # 'django.template.loaders.eggs.Loader', +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', ) MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', - # Uncomment the next line for simple clickjacking protection: - # 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ROOT_URLCONF = '{{ project_name }}.urls' -# Python dotted path to the WSGI application used by Django's runserver. WSGI_APPLICATION = '{{ project_name }}.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. -) -INSTALLED_APPS = ( - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - # Uncomment the next line to enable the admin: - # 'django.contrib.admin', - # Uncomment the next line to enable admin documentation: - # 'django.contrib.admindocs', -) +# Database +# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases -# A sample logging configuration. The only tangible logging -# performed by this configuration is to send an email to -# the site admins on every HTTP 500 error when DEBUG=False. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - } - }, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } + +# Internationalization +# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/django/conf/project_template/project_name/urls.py b/django/conf/project_template/project_name/urls.py index eb471d54a8..f03a29478d 100644 --- a/django/conf/project_template/project_name/urls.py +++ b/django/conf/project_template/project_name/urls.py @@ -1,17 +1,12 @@ from django.conf.urls import patterns, include, url -# Uncomment the next two lines to enable the admin: -# from django.contrib import admin -# admin.autodiscover() +from django.contrib import admin +admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', '{{ project_name }}.views.home', name='home'), - # url(r'^{{ project_name }}/', include('{{ project_name }}.foo.urls')), + # url(r'^blog/', include('blog.urls')), - # Uncomment the admin/doc line below to enable admin documentation: - # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), - - # Uncomment the next line to enable the admin: - # url(r'^admin/', include(admin.site.urls)), + url(r'^admin/', include(admin.site.urls)), ) diff --git a/django/conf/project_template/project_name/wsgi.py b/django/conf/project_template/project_name/wsgi.py index f768265b23..94d60c8cf9 100644 --- a/django/conf/project_template/project_name/wsgi.py +++ b/django/conf/project_template/project_name/wsgi.py @@ -1,32 +1,14 @@ """ WSGI config for {{ project_name }} project. -This module contains the WSGI application used by Django's development server -and any production WSGI deployments. It should expose a module-level variable -named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover -this application via the ``WSGI_APPLICATION`` setting. - -Usually you will have the standard Django WSGI application here, but it also -might make sense to replace the whole Django WSGI application with a custom one -that later delegates to the Django one. For example, you could introduce WSGI -middleware here, or combine a Django application with an application of another -framework. +It exposes the WSGI callable as a module-level variable named ``application``. +For more information on this file, see +https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/wsgi/ """ -import os -# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks -# if running multiple sites in the same mod_wsgi process. To fix this, use -# mod_wsgi daemon mode with each site in its own daemon process, or use -# os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings" +import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") -# This application object is used by any WSGI server configured to use this -# file. This includes Django's development server, if the WSGI_APPLICATION -# setting points here. from django.core.wsgi import get_wsgi_application application = get_wsgi_application() - -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application) diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 5ce50b4dfd..7904b72dd9 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -105,10 +105,15 @@ class TemplateCommand(BaseCommand): base_name = '%s_name' % app_or_project base_subdir = '%s_template' % app_or_project base_directory = '%s_directory' % app_or_project + if django.VERSION[-1] == 0: + docs_version = 'dev' + else: + docs_version = '%d.%d' % django.VERSION[:2] context = Context(dict(options, **{ base_name: name, base_directory: top_dir, + 'docs_version': docs_version, }), autoescape=False) # Setup a stub settings environment for template rendering diff --git a/django/views/debug.py b/django/views/debug.py index e5f4c70191..efab03f09c 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -438,9 +438,12 @@ def technical_404_response(request, exception): except (IndexError, TypeError, KeyError): tried = [] else: - if not tried: - # tried exists but is an empty list. The URLconf must've been empty. - return empty_urlconf(request) + if (not tried # empty URLconf + or (request.path == '/' + and len(tried) == 1 # default URLconf + and len(tried[0]) == 1 + and tried[0][0].app_name == tried[0][0].namespace == 'admin')): + return default_urlconf(request) urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) if isinstance(urlconf, types.ModuleType): @@ -458,12 +461,10 @@ def technical_404_response(request, exception): }) return HttpResponseNotFound(t.render(c), content_type='text/html') -def empty_urlconf(request): +def default_urlconf(request): "Create an empty URLconf 404 error response." - t = Template(EMPTY_URLCONF_TEMPLATE, name='Empty URLConf template') - c = Context({ - 'project_name': settings.SETTINGS_MODULE.split('.')[0] - }) + t = Template(DEFAULT_URLCONF_TEMPLATE, name='Default URLconf template') + c = Context({}) return HttpResponse(t.render(c), content_type='text/html') # @@ -1067,7 +1068,7 @@ TECHNICAL_404_TEMPLATE = """ </html> """ -EMPTY_URLCONF_TEMPLATE = """ +DEFAULT_URLCONF_TEMPLATE = """ <!DOCTYPE html> <html lang="en"><head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> @@ -1087,7 +1088,6 @@ EMPTY_URLCONF_TEMPLATE = """ tbody td, tbody th { vertical-align:top; padding:2px 3px; } thead th { padding:1px 6px 1px 3px; background:#fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px solid #ddd; } tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; } - ul { margin-left: 2em; margin-top: 1em; } #summary { background: #e0ebff; } #summary h2 { font-weight: normal; color: #666; } #explanation { background:#eee; } @@ -1103,11 +1103,10 @@ EMPTY_URLCONF_TEMPLATE = """ </div> <div id="instructions"> - <p>Of course, you haven't actually done any work yet. Here's what to do next:</p> - <ul> - <li>If you plan to use a database, edit the <code>DATABASES</code> setting in <code>{{ project_name }}/settings.py</code>.</li> - <li>Start your first app by running <code>python manage.py startapp [appname]</code>.</li> - </ul> + <p> + Of course, you haven't actually done any work yet. + Next, start your first app by running <code>python manage.py startapp [appname]</code>. + </p> </div> <div id="explanation"> |
