Django 1.8 TEMPLE_DIR and STATICFILES_DIRS Configuration
The TEMPLATE_DIRS template directory and STATICFILES_DIRS static Access Directory are not in the settings. py file after Django 1.6. You need to add them manually. Recently, this problem has been encountered. Let's talk about the solution.
1. Environment
System: Ubuntu
Django: Django-1.8.4.tar.gz
2. settings. py configuration file description
Added the following content:
Import OS
BASE_DIR = OS. path. dirname (OS. path. dirname (OS. path. abspath (_ file __)))
Base_dir is the directory of the project. The lower level of the project directory is the directory of the application app, and OS. path. dirname (_ file _): the directory where the settings. py file is located.
3. Specify the TEMPLATE_DIRS path and find the following code. The red part is the added TEMPLATE Directory, which is an empty list by default.
TEMPLATES = [
{
'Backend': 'django. template. backends. django. djangotemplates ',
# 'Backend': '/root/day10/s4web/templates ',
'Dirs': [OS. path. join (BASE_DIR, 'templates'). replace ('\', '/'),],
'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 ',
],
},
},
]
In fact, the following replace ('\', '/') can not be added. This sentence is used in windows to convert '\' '/'.
4. The STATICFILES_DIRS configuration is also relatively simple. Just add the following code at the end of settings. py.
STATICFILES_DIRS = (OS. path. join (BASE_DIR, 'static '),)
5. The configuration is complete.
Django1.8 returns the json string and the content of the json string that receives the post.
How to Use Docker components to develop a Django project?
Install Nginx + uWSGI + Django on Ubuntu Server 12.04
Deployment of Django + Nginx + uWSGI
Django tutorial
Build a Django Python MySQL Linux development environment
Django details: click here
Django's: click here
This article permanently updates the link address: