Access Apache SetEnv variable from Django wsgi.py file

前端 未结 5 1779
盖世英雄少女心
盖世英雄少女心 2020-12-14 09:53

I\'m trying to separate out Django\'s secret key and DB pass into environmental variables, as widely suggested, so I can use identical code bases between local/production se

5条回答
  •  佛祖请我去吃肉
    2020-12-14 10:29

    I ran into the same problem of separating production and development code while tracking both of them into version control. I solved the problem using different wsgi scripts, one for production server and one for development server. Create two different setting files as mentioned here. And reference them in wsgi scripts. For example the following is wsgi_production.py file

    ...
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.production")
    ...
    

    and in wsgi_development.py file

    ...
    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.development")
    ...
    

提交回复
热议问题