我们用django创建项目后,一般需要在$PROJECT/$PROJECT/settings.py文件中做些配置,例如配置templates和static目录的路径
templates的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
TEMPLATES = [
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
: [os.path.
join
(BASE_DIR,
'templates'
)],
'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'
,
],
},
},
]
|
static的配置,直接在settings文件末尾追加以下配置:
1
2
3
4
5
|
STATIC_URL =
'/static/'
STATICFILES_DIRS = (
os.path.
join
(BASE_DIR,
'static'
),
)
|
附上settings.py文件的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#coding=utf-8
import
os
SITE_NAME = u
'CMDB管理'
BASE_DIR = os.path.
dirname
(os.path.
dirname
(os.path.abspath(__file__)))
SECRET_KEY =
'e++_n#g$)mm!py&8r=ixbg=9ke@v*zc%%26asbm(^@=_qtoc93'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [
'*'
]
# Application definition
INSTALLED_APPS = (
'django.contrib.admin'
,
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'ucloud'
,
'api'
,
)
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 =
'cmdb.urls'
TEMPLATES = [
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
: [os.path.
join
(BASE_DIR,
'templates'
)],
'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 =
'cmdb.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default'
: {
'ENGINE'
:
'django.db.backends.sqlite3'
,
'NAME'
: os.path.
join
(BASE_DIR,
'db.sqlite3'
),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE =
'zh-CN'
TIME_ZONE =
'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL =
'/static/'
STATICFILES_DIRS = (
os.path.
join
(BASE_DIR,
'static'
),
)
|
本文转自 曾哥最爱 51CTO博客,原文链接:http://blog.51cto.com/zengestudy/1930837,如需转载请自行联系原作者