Django 1.8 TEMPLE_DIR and STATICFILES_DIRS Configuration

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.