setting源代碼
# 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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'w5l7yqw$4o@mf%!ydt)xz+aq-2^(lu@q&z4*8q_&oh5bi*8@nw'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
項(xiàng)目中安裝的APP
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
當(dāng)我們新創(chuàng)建一個(gè)APP時(shí),需要把APP添加到上面北专,例如上面新添加的blog APP(注意不要忘記末尾的",")
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'newsite.urls'
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',
],
},
},
]
WSGI_APPLICATION = 'newsite.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'blog', #數(shù)據(jù)庫的名字
'USER':'', #數(shù)據(jù)庫的用戶
'PASSWORD':'', #數(shù)據(jù)庫的用戶對(duì)應(yīng)的密碼
'HOST':'', #數(shù)據(jù)庫的地址
'PORT':'', #數(shù)據(jù)庫對(duì)應(yīng)的端口
}
}
重要補(bǔ)充:當(dāng)使用mysql最為數(shù)據(jù)庫時(shí),需要先使用命令行創(chuàng)建相應(yīng)的數(shù)據(jù)庫。
時(shí)區(qū)與語言設(shè)置
LANGUAGE_CODE = 'zh_cn'
TIME_ZONE = 'Asia/Shanghai'
注意要把時(shí)區(qū)和時(shí)間改成上述樣式。
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'