简体   繁体   English

如何在wsgi文件(Flask)中设置apache2环境变量

[英]How to set apache2 environment variables in wsgi file (Flask)

Currently I work with Flask micro framework. 目前,我正在使用Flask微框架。 How to set Environment variables in wsgi file? 如何在wsgi文件中设置环境变量? I have done this in apache2 envvars file like this: 我已经在apache2 envvars文件中做到了这一点:

export PRODROOT=${PRODROOT:-/home/peter/Lv-164.UI/ecomap}
export PYSRCROOT=${PYSRCROOT:-${PRODROOT}/src/python}
export CONFROOT=${CONFROOT:-${PRODROOT}/etc}
export PYTHONPATH=${PRODROOT}/src/python

How I can do that in wsgi file? 我如何在wsgi文件中做到这一点? Thanks for your attention. 感谢您的关注。

The wsgi file is just a Python file, so you can use os.environ to set environment variables for your code. wsgi文件只是一个Python文件,因此您可以使用os.environ为代码设置环境变量。 Eg in your wsgi file: 例如在您的wsgi文件中:

import os
os.environ['PRODROOT'] = '/home/peter/Lv-164.UI/ecomap'
os.environ['PYSRCROOT'] = os.environ['PRODROOT'] + '/src/python'
os.environ['CONFROOT'] = os.environ['PRODROOT'] + '/etc'
os.environ['PYTHONPATH'] = os.environ['PRODROOT'] + '/src/python'

from yourpackage.yourapp import app as application

I'm not sure that setting PYTHONPATH will work in this scenario (though it's worth a try). 我不确定在这种情况下设置PYTHONPATH是否可以使用(尽管值得尝试)。 If you're using mod_wsgi then you can set it with the WSGIPythonPath directive. 如果您使用的是mod_wsgi则可以使用WSGIPythonPath指令进行设置。

https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM