Deployment suggestions for the settings file in the Django framework of Python

Source: Internet
Author: User
This article describes how to deploy the settings file in the Python Django framework, including some simple analysis of the disadvantages of local_settings, for more information, see django's lack of necessary standards in the directory structure division of a project, in addition, it is hard to say who is doing better. According to my project organization habits, I released a project dj-scaffold.

A few days ago I made an "advertisement" for my project dj-scaffold on reddit (see http://redd.it/kw5d4 ). I don't want to make a bad comments, or even get a negative score. The project is not worth mentioning. Although it is uncomfortable to face negative voices, constructive comments need to be listened to. Those purely personal preferences are automatically filtered out.

Coderanger recommends that you refer to The Best (and Worst) of Django practices when talking about how to organize The settings file. The main point in this article is that the configuration of the development environment and production environment must be put into VCS for version control. I have made some adjustments to the settings module. Note: Code https://github.com/vicalloy/dj-scaffold/tree/master/dj_scaffold/conf/prj/sites/settings
Disadvantages of local_settings

To distinguish the default configuration of a project from the local configuration, add a local_settings.py file and import the file at the end of the settings file.

try: from local_settings import *except: pass 

The problem is that you cannot control the version of local_settings.py. If the configuration of the deployment environment is lost, it will be difficult to retrieve it.
Solution

The recommended solution is as follows:
Reasonable configuration file organization

The Code is as follows:

| ~ Settings/
|-_ Init _. py
|-Base. py # default configuration information
|-Dev. py # Development Environment Configuration
|-Local. sample # import the local extension configuration at the end of dev and production
|-Pre. sample # set the current configuration to the production environment or development environment
| '-Production. py # production environment Configuration

Usage

DJANGO_SETTINGS_MODULE 

The admin script of django provides the settings parameter to specify the currently used configuration file.

django-admin.py shell --settings=settings.dev 

In the wsgi script, you can directly set the settings to be used.

deploy.wsgios.environ['DJANGO_SETTINGS_MODULE'] = settings.production 

Simplified Parameters

Of course, it is annoying to include the settings parameter every time you use the django-admin.py, so it is recommended to configure the configuration file you need in pre. py.

SETTINGS = 'production' #dev 

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.