Quick Serve Python WSGI Application
17.09.2014Make new directory and create sample python WSGI application. Copy the following code and save it as sample2.py:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return ["<p>Hello NXWEB!</p>"]
Launch nxweb:
nxweb -T python -W sample2.application
Now visit the following location:
http://localhost:8055/
How this works
When nxweb is launched it looks for nxweb_config.json file, first in current working directory, then in default system-wide config directory (usually /usr/local/etc/nxweb when nxweb has been built from source).
Default shipped nxweb_config.json contains two simple rules: serve static files, and serve Python app.
-T python triggers the second rule.
-W sample2.application specifies Python module and name of the application.
You can also use -P dir switch to specify root directory for Python module search.
You can serve both static files and Python app by using the following command:
nxweb -T python,static -P ../python -W sample2.application
This setup expects sample2.py in ../python directory, and static files will be served from current working directory.
VirtualEnv
You can specify path to virtualenv environment via command line switch -V:
nxweb -T python -W sample2.application -V path/to/env
Comments