Django18初体验


1445 浏览 6 years, 1 month

7 配置概述

版权声明: 转载请注明出处 http://www.codingsoho.com/
(trydjango18) D:\virtualdir\trydjango18\src>tree /F
D:.
│  db.sqlite3
│  manage.py
│
├─newsletter
│  │  admin.py
│  │  models.py
│  │  tests.py
│  │  views.py
│  │  __init__.py
│  │
│  └─migrations
│          __init__.py
│
└─trydjango18
        settings.py
        settings.pyc
        urls.py
        urls.pyc
        wsgi.py
        wsgi.pyc
        __init__.py
        __init__.pyc
"""
Django settings for trydjango18 project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
[https://docs.djangoproject.com/en/1.8/topics/settings/](https://docs.djangoproject.com/en/1.8/topics/settings/)
For the full list of settings and their values, see
[https://docs.djangoproject.com/en/1.8/ref/settings/](https://docs.djangoproject.com/en/1.8/ref/settings/)
"""

BASE_DIR

返回当前路径

import os.path
os.path.dirname(__file__)

项目根目录

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#root of project
ROOT_URLCONF = 'trydjango18.urls'

MIDDLEWARE_CLASSES
介于request和response之间

TEMPLATES

A list containing the settings for all template engines to be used with Django. Each item of the list is a dictionary containing the options for an individual engine.
Here’s a simple setup that tells the Django template engine to load templates from the templates subdirectory inside each installed application:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

TEMPLATE_DIRS

Default: () (Empty tuple)
Deprecated since version 1.8: Set the DIRS option of a DjangoTemplates backend instead.
List of locations of the template source files searched by django.template.loaders.filesystem.Loader, in search order.
Note that these paths should use Unix-style forward slashes, even on Windows.

TEMPLATE_CONTEXT_PROCESSORS

Default:

(
    "django.contrib.auth.context_processors.auth",
    "django.template.context_processors.debug",
    "django.template.context_processors.i18n",
    "django.template.context_processors.media",
    "django.template.context_processors.static",
    "django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages"
)

Deprecated since version 1.8: Set the 'context_processors' option in the OPTIONS of a DjangoTemplates backend instead.
A tuple of callables that are used to populate the context in RequestContext. These callables take a request object as their argument and return a dictionary of items to be merged into the context.
Changed in Django 1.8:
Built-in template context processors were moved from django.core.context_processors to django.template.context_processors in Django 1.8.

TEMPLATE_LOADERS

Default:

(
    'django.template.loaders.filesystem.Loader',
     'django.template.loaders.app_directories.Loader'
)

Deprecated since version 1.8: Set the 'loaders' option in the OPTIONS of a DjangoTemplates backend instead.
A tuple of template loader classes, specified as strings. Each Loader class knows how to import templates from a particular source. Optionally, a tuple can be used instead of a string. The first item in the tuple should be the Loader’s module, subsequent items are passed to the Loader during initialization. See The Django template language: for Python programmers.