Deployment recommendations for settings files in the Python Django framework

Source: Internet
Author: User
Django lacks the necessary specifications for a project's directory structure, so different people have a variety of project forms, and it's hard to say who's doing it better. I have published a project Dj-scaffold according to my own project organizational habits.

A few days ago on the Reddit for my project Dj-scaffold played an "advertisement" (see: HTTP://REDD.IT/KW5D4). Do not want to judge very bad, even almost to be beaten into negative points. One of the more people will say that the project is worthless. While there is some discomfort in the face of negative voices, the constructive advice needs to be heard, and those purely personal preferences are automatically filtered.

When talking about how settings files are organized, Coderanger recommends referencing the best (and worst) of the Django practices. The main idea is that both the development environment and the configuration of the production environment need to be placed in VCs for version control. I have made some adjustments to the settings module by referring to the practice in the article. Note: Code https://github.com/vicalloy/dj-scaffold/tree/master/dj_scaffold/conf/prj/sites/settings
The ills of local_settings

To separate the project's default configuration from the local configuration, the most common practice is to add a local_settings.py file and import the file at the end of the settings file.

The problem with this is that you cannot version control the local_settings.py, and the configuration of the deployment environment will be difficult to retrieve in case of loss.
Solution Solutions

The recommended solution for this issue is as follows
How to organize a reasonable configuration file

Copy the Code code as follows:

|~settings/
| |-__init__.py
| |-base.py #默认配置信息
| |-dev.py #开发环境的配置
| |-local.sample #本地的扩展配置在dev和production的最后进行import
| |-pre.sample #设置当前使用的配置为生产环境还是开发环境
| '-production.py #生产环境的配置

How to use

Django_settings_module

The Django Admin script provides the settings parameter for specifying the currently used configuration file

In the Wsgi script, you can set the settings that you want to use directly

Simplifying parameters

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

  • Related Article

    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.