Skip to content
Myr

cgi.rst

This file

Path

docs/deploying/cgi.rst

61 lines · 2.0 KiB

Last changed by

Merge pull request #654 from untitaker/print_in_cgi2Armin Ronacherbefore adoption7ec45c2

History of this file

Take it

The walk stopped after 200 commits: lines older than 2053d04 point at it.

Improved interface for the URL build error handlerArmin Ronacherbefore adoption2053d04

lines 1–18why, 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.18

Merge pull request #647 from untitaker/print_in_cgiKenneth Reitzbefore adoption8131496

line 19why, one step back
19 With CGI, you will also have to make sure that your code does not contain

Merge pull request #654 from untitaker/print_in_cgi2Armin Ronacherbefore adoption7ec45c2

line 20why, one step back
20 any ``print`` statements, or that ``sys.stdout`` is overridden by something

Merge pull request #647 from untitaker/print_in_cgiKenneth Reitzbefore adoption8131496

lines 21–22why, one step back
21 that doesn't write into the HTTP response.
22

Improved interface for the URL build error handlerArmin Ronacherbefore adoption2053d04

lines 23–41why, one step back
23Creating a `.cgi` file
24----------------------2526First you need to create the CGI application file. Let's call it27`yourapplication.cgi`::2829 #!/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 the39`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to40rewrite the URL) or let the server point to the file directly.41

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5

line 42why, one step back
42In Apache for example you can put something like this into the config:

Improved interface for the URL build error handlerArmin Ronacherbefore adoption2053d04

lines 43–46why, one step back
43
44.. sourcecode:: apache4546 ScriptAlias /app /path/to/the/application.cgi

Merge branch 'master' of github.com:mitsuhiko/flaskArmin Ronacherbefore adoption2e816f5

lines 47–57why, one step back
47
48On shared webhosting, though, you might not have access to your Apache config.49In this case, a file called `.htaccess`, sitting in the public directory you want50your app to be available, works too but the `ScriptAlias` directive won't51work in that case:5253.. sourcecode:: apache54 55 RewriteEngine On56 RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files57 RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L]

Improved interface for the URL build error handlerArmin Ronacherbefore adoption2053d04

lines 58–61why, one step back
58
59For more information consult the documentation of your webserver.6061.. _App Engine: http://code.google.com/appengine/