Reputation: 21
So I want to invoke different instances of Python code based on user's URL (or at least user's domain) from WSGI file. We're running on Apache 2.x + Python + Django stack.
Looks like there should be something like 'SERVER_NAME' or 'HTTP_HOST' key in the os.environ
dictionary accessible in WSGI script (here and here). However this key is missing and here's how os.environ.__dict__
looks like when everything is working properly:
{'data': {'LANG': 'C', 'APACHE_LOCK_DIR': 'xxx', 'TZ': 'US/Pacific', 'DJANGO_SETTINGS_MODULE': 'xxx', 'APACHE_RUN_USER': 'xxx', 'PWD': 'xxx', 'APACHE_PID_FILE': 'xxx', 'CELERY_LOADER': 'django', 'APACHE_RUN_DIR': 'xxx', 'APACHE_LOG_DIR': 'xxx', 'APACHE_RUN_GROUP': 'xxx', 'HOME': 'xxx', 'PATH': 'xxx'}}
Domain/URL is a very basic info and I'm surprised I'm failing to find it.
UPDATE: I've settled on a different approach (using Apache Config instead WSGI script). That seems to solve the issue of missing WSGI environment variable. Thanks for all your responses!
Upvotes: 2
Views: 1215
Reputation: 599590
You're confusing the os.environ
dict that shows the current system environment variables with the environ
that is passed to the wsgi application as a parameter. The path is in the latter.
However, since you're using Django, that information is all made available via the request
object.
Upvotes: 3