cgi.rst
This file
The walk stopped after 200 commits: lines older than 0748e2d point at it.
Fix typo in changelogMarkus Unterwaditzerbefore adoption0748e2d
lines 1–61why, one step back1CGI2===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 it27:file:`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 :file:`cgi-bin` (and use `mod_rewrite` or something similar to40rewrite 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.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:: 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/