<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Werkzeug Documentation</title> <link rel="stylesheet" href="../_static/style.css" type="text/css"> <link rel="stylesheet" href="../_static/print.css" type="text/css" media="print"> <link rel="stylesheet" href="../_static/pygments.css" type="text/css"> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '0.6.1' }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/interface.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/werkzeug.js"></script> <link rel="contents" title="Global table of contents" href="../contents.html"> <link rel="index" title="Global index" href="../genindex.html"> <link rel="search" title="Search" href="../search.html"> <link rel="top" title="Werkzeug v0.6.1 documentation" href="../index.html"> <link rel="up" title="Application Deployment" href="index.html"> <link rel="next" title="mod_wsgi (Apache)" href="mod_wsgi.html"> <link rel="prev" title="Application Deployment" href="index.html"> </head> <body> <div class="page"> <div class="header"> <h1 class="heading"><a href="../index.html" title="back to the documentation overview"><span>Werkzeug</span></a></h1> </div> <ul class="navigation"> <li class="indexlink"><a href="../index.html">Overview</a></li> <li><a href="index.html">« Application Deployment</a></li> <li class="active"><a href="#">CGI</a></li> <li><a href="mod_wsgi.html"><cite>mod_wsgi</cite> (Apache) »</a></li> </ul> <div class="body"> <div id="toc"> <h3>Table Of Contents</h3> <div class="inner"><ul> <li><a class="reference external" href="#">CGI</a><ul> <li><a class="reference external" href="#creating-a-cgi-file">Creating a <cite>.cgi</cite> file</a></li> <li><a class="reference external" href="#server-setup">Server Setup</a></li> </ul> </li> </ul> </div> </div> <div class="section" id="cgi"> <h1>CGI<a class="headerlink" href="#cgi" title="Permalink to this headline">¶</a></h1> <p>If all other deployment methods do not work, CGI will work for sure. CGI is supported by all major servers but usually has a less-than-optimal performance.</p> <p>This is also the way you can use a Werkzeug application on Google’s <a class="reference external" href="http://code.google.com/appengine/">AppEngine</a>, there however the execution does happen in a CGI-like environment. The application’s performance is unaffected because of that.</p> <div class="section" id="creating-a-cgi-file"> <h2>Creating a <cite>.cgi</cite> file<a class="headerlink" href="#creating-a-cgi-file" title="Permalink to this headline">¶</a></h2> <p>First you need to create the CGI application file. Let’s call it <cite>yourapplication.cgi</cite>:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/python</span> <span class="kn">from</span> <span class="nn">wsgiref.handlers</span> <span class="kn">import</span> <span class="n">CGIHandler</span> <span class="kn">from</span> <span class="nn">yourapplication</span> <span class="kn">import</span> <span class="n">make_app</span> <span class="n">application</span> <span class="o">=</span> <span class="n">make_app</span><span class="p">()</span> <span class="n">CGIHandler</span><span class="p">()</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">application</span><span class="p">)</span> </pre></div> </div> <p>If you’re running Python 2.4 you will need the <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/wsgiref.html#module-wsgiref"><tt class="xref py py-mod docutils literal"><span class="pre">wsgiref</span></tt></a> package. Python 2.5 and higher ship this as part of the standard library.</p> </div> <div class="section" id="server-setup"> <h2>Server Setup<a class="headerlink" href="#server-setup" title="Permalink to this headline">¶</a></h2> <p>Usually there are two ways to configure the server. Either just copy the <cite>.cgi</cite> into a <cite>cgi-bin</cite> (and use <cite>mod_rerwite</cite> or something similar to rewrite the URL) or let the server point to the file directly.</p> <p>In Apache for example you can put a like like this into the config:</p> <div class="highlight-apache"><div class="highlight"><pre><span class="nb">ScriptAlias</span> <span class="sx">/app</span> <span class="sx">/path/to/the/application.cgi</span> </pre></div> </div> <p>For more information consult the documentation of your webserver.</p> </div> </div> <div style="clear: both"></div> </div> <div class="footer"> © Copyright 2008 by the <a href="http://pocoo.org/">Pocoo Team</a>, documentation generated by <a href="http://sphinx.pocoo.org/">Sphinx</a> </div> </div> </body> </html>