Skip to content
Myr

cgi.rst

This file

Path

docs/deploying/cgi.rst

61 lines · 2.0 KiB

Last changed by

Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae

History of this file

Take it

The walk stopped after 200 commits: lines older than 7b3e52b point at it.

Merge pull request #1217 from jeffwidman/patch-1Markus Unterwaditzerbefore adoption7b3e52b

lines 1–26why, one step back
1CGI
2===34If all other deployment methods do not work, CGI will work for sure.5CGI is supported by all major servers but usually has a sub-optimal6performance.78This is also the way you can use a Flask application on Google's `App9Engine`_, where execution happens in a CGI-like environment.1011.. admonition:: Watch Out1213 Please make sure in advance that any ``app.run()`` calls you might14 have in your application file are inside an ``if __name__ ==15 '__main__':`` block or moved to a separate file. Just make sure it's16 not called because this will always start a local WSGI server which17 we do not want if we deploy that application to CGI / app engine.1819 With CGI, you will also have to make sure that your code does not contain20 any ``print`` statements, or that ``sys.stdout`` is overridden by something21 that doesn't write into the HTTP response.2223Creating a `.cgi` file24----------------------2526First you need to create the CGI application file. Let's call it

Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae

line 27why, one step back
27:file:`yourapplication.cgi`::

Merge pull request #1217 from jeffwidman/patch-1Markus Unterwaditzerbefore adoption7b3e52b

lines 28–38why, one step back
28
29 #!/usr/bin/python30 from wsgiref.handlers import CGIHandler31 from yourapplication import app3233 CGIHandler().run(app)3435Server Setup36------------3738Usually there are two ways to configure the server. Either just copy the

Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae

line 39why, one step back
39``.cgi`` into a :file:`cgi-bin` (and use `mod_rewrite` or something similar to

Merge pull request #1217 from jeffwidman/patch-1Markus Unterwaditzerbefore adoption7b3e52b

lines 40–48why, one step back
40rewrite the URL) or let the server point to the file directly.
4142In Apache for example you can put something like this into the config:4344.. sourcecode:: apache4546 ScriptAlias /app /path/to/the/application.cgi4748On shared webhosting, though, you might not have access to your Apache config.

Merge pull request #1240 from defuz/docs-style-fix-2Markus Unterwaditzerbefore adoption6fcc2ae

lines 49–50why, one step back
49In this case, a file called ``.htaccess``, sitting in the public directory you want
50your app to be available, works too but the ``ScriptAlias`` directive won't

Merge pull request #1217 from jeffwidman/patch-1Markus Unterwaditzerbefore adoption7b3e52b

lines 51–61why, one step back
51work in that case:
5253.. sourcecode:: apache5455 RewriteEngine On56 RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files57 RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L]5859For more information consult the documentation of your webserver.6061.. _App Engine: https://developers.google.com/appengine/