cgi.rst
This file
Path
docs/deploying/cgi.rst
50 lines · 1.6 KiB
Last changed by
Merge branch 'master' into config-supportArmin Ronacherbefore adoption78fc994
History of this fileTake it
The walk stopped after 200 commits: lines older than 78fc994 point at it.
Merge branch 'master' into config-supportArmin Ronacherbefore adoption78fc994
lines 1–50why, one step back1CGI2===34If all other deployment methods do not work, CGI will work for sure. CGI5is supported by all major servers but usually has a less-than-optimal6performance.78This is also the way you can use a Flask application on Google's9`App Engine`_, there however the execution does happen in a CGI-like10environment. The application's performance is unaffected because of that.1112.. admonition:: Watch Out1314 Please make sure in advance that your ``app.run()`` call you might15 have in your application file, is inside an ``if __name__ ==16 '__main__':`` or moved to a separate file. Just make sure it's not17 called because this will always start a local WSGI server which we do18 not want if we deploy that application to CGI / app engine.1920.. _App Engine: http://code.google.com/appengine/2122Creating a `.cgi` file23----------------------2425First you need to create the CGI application file. Let's call it26`yourapplication.cgi`::2728 #!/usr/bin/python29 from wsgiref.handlers import CGIHandler30 from yourapplication import app3132 CGIHandler().run(app)3334If you're running Python 2.4 you will need the :mod:`wsgiref` package. Python352.5 and higher ship this as part of the standard library.3637Server Setup38------------3940Usually there are two ways to configure the server. Either just copy the41`.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to42rewrite the URL) or let the server point to the file directly.4344In Apache for example you can put a like like this into the config:4546.. sourcecode:: apache4748 ScriptAlias /app /path/to/the/application.cgi4950For more information consult the documentation of your webserver.