Demian Brecht
Demian Brecht

Reputation: 21378

Adding parameters to the wsgi script alias

Is there a way to pass extra arguments to WSGIScriptAlias? For example:

WSGIScriptAlias / /foo/bar/wsgi.py but what I want is:

WSGIScriptAlias / /foor/bar/wsgi.py baz

Edit for clarification:

I have a Django project with multiple configurations based on the environment in which it is running (cloud-based deployment). Currently, I'm loading configuration based on hostname (which I'm not overly happy with because it doesn't lend itself well to testing multiple configs on one machine without changing the system's hostname). So, another solution would be to pass in command line arguments to the application and load the config in the WSGI entry point, which is relatively trivial when running the dev server, but I'm not aware of any way to do it via Apache/WSGI.

Upvotes: 4

Views: 3760

Answers (2)

user3788120
user3788120

Reputation: 607

If you are using mod_wsgi, you may take advantage of envvars options when setting up.

For example:

mod_wsgi-express start-server ./my-wsgi.py --port 8200 --envvars-script /home/user/envvars_localhost.sh

in the envvars file "envvars_localhost.sh", set some needed parameter:

#!/bin/bash
export MOD_WSGI_VARIABLE='config1'

then at runtime your ./my-wsgi.py can reference the data:

mylocalConfigValue = os.environ['MOD_WSGI_VARIABLE']

Upvotes: 0

Graham Dumpleton
Graham Dumpleton

Reputation: 58563

First up, ensure you are using daemon mode, it is preferred anyway.

Then inside of your WSGI script file you can do:

import mod_wsgi

process_group = mod_wsgi.process_group

You can then use the name of the process group as a way of distinguishing which configuration.

In other words, use the name of the daemon process group you choose to use in the Apache configuration file as the distinguishing factor.

Upvotes: 4

Related Questions