在这里不详细说明每一条的配置,只对重要的进行说明:
接上一篇“环境配置”中新建的工程,在hello目录会有一个setting文件。修改此文件,或许直接上个已经配好的文件更能说明问题。
DEBUG = True #正式发布时,改成False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
LOGIN_URL = '/login/' #未登陆用户跳转到此url
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__)) #get the directory path of this script
path=SETTINGS_PATH.split('\\')
SET_PATH='/'.join(path[:len(path)-1]) #get the upper level directory
#静态文件目录
STATICFILES_DIRS = (
('common_static', ''.join([SET_PATH, '/static/common_static']).replace('\\','/')),
)
STATIC_ROOT = ''.join([SET_PATH, '/static']).replace('\\','/')
# URL prefix for static files.
STATIC_URL = '/static/' #configure the url path for using replace for the STATICFILES_DIRS
#模板目录
TEMPLATE_DIRS = (
''.join([SET_PATH, '/templates']).replace('\\','/'),
os.path.join(os.path.dirname(__file__), 'templates'),
)
#SAE mysql配置 兼容本地mysql,会自动判断
if 'SERVER_SOFTWARE' in os.environ:
from sae.const import (
MYSQL_HOST, MYSQL_PORT, MYSQL_USER, MYSQL_PASS, MYSQL_DB
)
else:
# Make `python manage.py syncdb` works happy!
MYSQL_HOST = 'localhost'
MYSQL_PORT = '3306'
MYSQL_USER = 'root'
MYSQL_PASS = 'root'
MYSQL_DB = 'app_pylabs'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': MYSQL_DB,
'USER': MYSQL_USER,
'PASSWORD': MYSQL_PASS,
'HOST': MYSQL_HOST,
'PORT': MYSQL_PORT,
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.4/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
#根url配置文件
ROOT_URLCONF = 'hello.urls'
#安装的app
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',
'hello',
)
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'wxshop.wsgi.application'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'ia!818wkbn_h$k@ss%i#%zb1he744ef@_w*xllok=z8^qh6+vg'
# 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',
)
# 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',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'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',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request"
)
#语言
LANGUAGE_CODE = 'zh-cn'
#时区,影响时间
TIME_ZONE = 'Asia/Shanghai'
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
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# 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,
},
}
}
下一篇 创建app