Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 35fd6eb point at it.

Use uppercase for config and support any object.Armin Ronacherbefore adoption35fd6eb

lines 1–8why, one step back
1CGI
2===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's

Merge branch 'master' into config-supportArmin Ronacherbefore adoption78fc994

line 9why, one step back
9`App Engine`_, there however the execution does happen in a CGI-like

Use uppercase for config and support any object.Armin Ronacherbefore adoption35fd6eb

lines 10–17why, one step back
10environment. 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 do

Merge branch 'master' into config-supportArmin Ronacherbefore adoption78fc994

line 18why, one step back
18 not want if we deploy that application to CGI / app engine.

Use uppercase for config and support any object.Armin Ronacherbefore adoption35fd6eb

line 19why, one step back
19

Merge branch 'master' into config-supportArmin Ronacherbefore adoption78fc994

line 20why, one step back
20.. _App Engine: http://code.google.com/appengine/

Use uppercase for config and support any object.Armin Ronacherbefore adoption35fd6eb

lines 21–50why, one step back
21
22Creating 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.