I need to split Django's development and production settings. I decided that if USKOVTASK_PROD
variable is set, then app should use production settings. I read this article and tried to do it.
My snippets:
/etc/apache2/sites-enabled/uskovtask.conf:
<VirtualHost *:80>
ServerName uskovtask.*.com
ServerAlias uskovtask.*.com
DocumentRoot /mnt/ebs/uskovtask
Alias /static /mnt/ebs/uskovtask/static/
<Directory /mnt/ebs/uskovtask/static>
Require all granted
</Directory>
#WSGIPythonPath /mnt/ebs/uskovtask
WSGIDaemonProcess uskovtask.*.com python-path=/mnt/ebs/uskovtask:/usr/lib/python2.7/site-packages
WSGIProcessGroup uskovtask.*.com
WSGIScriptAlias / /mnt/ebs/uskovtask/uskovtask/wsgi.py
SetEnv USKOVTASK_PROD 1
<Directory /mnt/ebs/uskovtask/uskovtask>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "uskovtask.settings")
from django.core.wsgi import get_wsgi_application
_application = get_wsgi_application()
def application(environ, start_response):
if 'USKOVTASK_PROD' in environ:
os.environ.setdefault('USKOVTASK_PROD', environ['USKOVTASK_PROD'])
return _application(environ, start_response)
settings.py's part:
import os
if 'USKOVTASK_PROD' in os.environ:
from settings_prod import *
else:
from settings_dev import *
But it always imports settings_dev's settings. Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…