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_ENV
At 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?
at
/etc/apache2/envvars
中设置export Z_ENV=server