Home  >  Article  >  Backend Development  >  How to Manage Django Settings for Local Development and Production?

How to Manage Django Settings for Local Development and Production?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-02 16:48:02217browse

How to Manage Django Settings for Local Development and Production?

Separating Local and Production Django Settings

Managing Django settings across local development and production environments can be a challenge. Some settings, such as constants, can be shared between both while others, like file paths, require variation.

The recommended approach, as outlined in "Two Scoops of Django," is to employ version control and store settings in a dedicated directory within your project:

project/
    app1/
    app2/
    project/
        __init__.py
        settings/
            __init__.py
            base.py
            local.py
            production.py
    manage.py

Common Settings in base.py

settings/base.py houses settings shared across both environments, such as MEDIA_ROOT and ADMIN.

Site-Specific Settings

  • settings/local.py contains settings specific to local development, such as DEBUG and development apps.
  • settings/production.py holds settings for the production site, including any necessary app additions.

Executing Django with Specified Settings

When running Django commands, utilize the --settings option to specify the appropriate settings file:

  • Local development: ./manage.py runserver 0:8000 --settings=project.settings.local
  • Production shell: ./manage.py shell --settings=project.settings.production

Sample Project Template

For further guidance, a sample project layout template is available on GitHub.

The above is the detailed content of How to Manage Django Settings for Local Development and Production?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn