Skip to content
Myr

cgi.rst

This file

Path

docs/deploying/cgi.rst

61 lines · 2.0 KiB

Last changed by

Merge branch '1.0.x'David Lordbefore adoption1351d0a

History of this file

Take it

The walk stopped after 200 commits: lines older than 4a7db66 point at it.

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

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

Merge pull request #3175 from singingwolfboy/fix-rst-line-too-longDavid Baumgoldbefore adoption819368a

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

Merge pull request #2636 from pallets/test-cli-runnerDavid Lordbefore adoption4a7db66

lines 52–60why, one step back
52
53.. 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.60

Merge branch '1.0.x'David Lordbefore adoption1351d0a

line 61why, one step back
61.. _App Engine: https://cloud.google.com/appengine/docs/