On 01/08/2012 09:48, Damjan Georgievski wrote:
I'm having an impossible time getting a Flask app to see any environment
variables I try and pass through from nginx using the "uwsgi_param
UWSGI_SETENV VARNAME=FOO" method.

Trying to access these vars via os.environ['VARNAME'] always throws a
KeyError exception. Interestingly, passing an env variable to the Flask app
via the uwsgi config file itself works as expected.

The Flask app is running as a vassal of the emperor (in its own virtualenv)
and copied below are the relevant bits of my config.
I think you need to run uwsgi in "dynamic" mode for that to work.
"dynamic" mode is when you don't specify an application to run.



Thanks Damjan. That's a little frustrating because I'd very much prefer to stick with the emperor + config file method rather than going dynamic.

The reason I'm trying to set a couple of ENV vars in nginx and then pass them through to Flask is due to internationalization. What I wanted to achieve was a setup where I could register domain.com, domain.it, domain.es, domain.de, domain.co.uk etc. and have all of these domains hosted on the same nginx instance, pointing to the same Flask app. I then wanted to pass through a language environment var based on which nginx vhost a client used to access the site (so that Flask could then serve the app in the correct language).

Doing it this way was appealing because the Flask app wouldn't need to care about what domains (or subdomains) exist. It would simply grab the language ENV var set by nginx and render accordingly (or default to english if no var was present).

Charlie



_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to