django - Gunicorn Environment Variable Setting -


I am currently having difficulty crossing the environmental variable in Gonicorn for my own project. I'm on the latest version 19.1 I have a wsgi.py file like this:

import import from sys django.core.wsgi get_wsgi_application BASE_DIR = os.path.dirname (os.path.abspath (__ file__ )) PROJECT_DIR = Os.path.abspath (os.path.join (BASE_DIR, '..')) sys.path.append (PROJECT_DIR) os.environ.setdefault ("DJANGO_SETTINGS_MODULE", "Apps Settings") Def App (Environment, ['SERVER_ID'] OS environment ['SERVER_ENV'] os.environ ['SERVER_ID'] = Environment ['SERVER_ID'] Return _pakication (environment, start_progress) / Pre>

When I run the Gnocorn from the command line:

  SERVER_ENV = test SERVER_ID = test guanacore - b 127.0.0.1:8080 - Terror-logfile - - Access-Logfile - app.wsgi: application  

And then I pass a request for the Ganoikorn which I keep: / P>

  2014-08-01 08:39:17 [21462] [Error] Error traceback handling the request (most recent call final): file "/opt/virtualenv/python-2.7 Self.handle_request (listener, request, client, adr) file in "/ opt / / / django-1.5.5 / lib / pyt Hon2.7 / site-packages / gunicorn / workers / sync.py", line 93, Virtualenv / python-2.7.5 / django-1.5 .5 / lib / python2.7 / site-packages / gunicorn / workers / sync.py ", line 134, handle_request respiter = self.wsgi (and Tavarn, resp.start_response) file "/ opt / sites / itracker / in wsgi. Confirms to print the values ​​of the environment that the environmental variable I have not passed. I tried to set environment variables in the Virtual AVI activation script, and it is also not working in dedicated donnons shell script as well as by installing environment variables using ANV flag.  

Any thoughts?

All you have to do is export your environment variable.

  Export SERVER_ENV = Test Export SERVER_ID = Test Gnocorn-B 127.0.0.1:8 080 - Terror-logfile - - Login-logfile - App.Usage: App  

And you can get them in your code like that

  os .getenv ('SERVER_ENV')  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -