django - Problem reading environment variables when apache loads the configuration file
天蓬老师
天蓬老师 2017-05-16 17:03:31
0
1
618

My project is deployed using django + apache. In order to easily distinguish between online and development environments, I set an environment variable Z_ENV on the server, and then in the Django configuration file it looks like this written,

env = os.environ.get("Z_ENV", None)
if env == "server":
    from .server_settings import *
else:
    from .local_settings import *

This way of writing is no problem using some of the commands that come with Django locally or on the server, such as directly running os.environ.get("Z_ENV", None)is server or python managa.py syncdb is indeed using the configuration in server_settings, but this environment variable is not obtained when apache loads the configuration file, and then I used local_settings. I added print env above, and then when service apache2 restart was printed, None was printed in the apache log file. .

The environment variable is modified in the /etc/profile file, the content is Z_ENV=server export Z_ENVAt first, it did not take effect for apache users, but then I checked Check, the environment variables set here are effective for all users.

Let’s ask everyone what’s going on?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
迷茫

at /etc/apache2/envvars 中设置 export Z_ENV=server

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template