Search code examples
djangogithubversion-controldevelopment-environmentproduction-environment

How to properly manage django production and development files


  1. How can I properly manage my development files and production files with source control like GitHub (private repo). I am new to Django and while publishing my code to production there are many settings which needs to be changed in order to use it in production but the same setting won't work on my development server. I am stuck here Please guide me how manage. I want my files to be source control like any time I can make my development environment on another pc and anytime I can make my production server on any server.

  2. how to manage secret keys, passwords on source control (like GitHub private repo)

  3. Also please specify how should an Ideal file structure look like


Solution

  • hope you are well.

    To answer the following questions I will do so based in the format you have asked.

    1. You ask about management of production and development files with source control (namely GitHub). It would be best to store these in different branches of source control. Example: "main" branch being used for production and a "development" branch being used for development. This will allow you to work with both branches and you can merge development branch into the production branch.

    2. The best way you can manage sensitive information such as passwords and keys in source control is to avail of .env files (What is the use of python-dotenv?), which stores variables in an environment. You can store variables in this file and tell GitHub to ignore this file in the .gitignore file.

    3. You mention ideal file structure. There are many ways which files can be structured and normally I would say this is preference on the developers behalf as this doesn't really matter as long as the developer and future developers can make sense of the file structure. From personal recommendation and this is my own opinion.

    Project setup

    • staticfiles folder
    • projectName
      • settings.py etc
    • app
      • app files
    • manage.py

    Hope this can be of some benefit to you and some clarity around your questions.

    Have a good day.