django settings配置templates和static
我们用django创建项目后,一般需要在$PROJECT/$PROJECT/settings.py文件中做些配置,例如配置templates和static目录的路径
templates的配置:
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文件末尾追加以下配置:
STATIC_URL='/static/'STATICFILES_DIRS=(os.path.join(BASE_DIR,'static'),)
附上settings.py文件的内容:
#coding=utf-8importosSITE_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'#SECURITYWARNING:don'trunwithdebugturnedoninproduction!DEBUG=TrueALLOWED_HOSTS=['*']#ApplicationdefinitionINSTALLED_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/#databasesDATABASES={'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=TrueUSE_L10N=TrueUSE_TZ=False#Staticfiles(CSS,JavaScript,Images)#https://docs.djangoproject.com/en/1.8/howto/static-files/STATIC_URL='/static/'STATICFILES_DIRS=(os.path.join(BASE_DIR,'static'),)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。