/usr/share/doc/python-werkzeug-doc/html/serving.html is in python-werkzeug-doc 0.10.4+dfsg1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Serving WSGI Applications — Werkzeug 0.10.4 documentation</title>
<link rel="stylesheet" href="_static/werkzeug.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.10.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Werkzeug 0.10.4 documentation" href="index.html" />
<link rel="next" title="Test Utilities" href="test.html" />
<link rel="prev" title="Python 3 Notes" href="python3.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="test.html" title="Test Utilities"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="python3.html" title="Python 3 Notes"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Werkzeug 0.10.4 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-werkzeug.serving">
<span id="serving-wsgi-applications"></span><h1>Serving WSGI Applications<a class="headerlink" href="#module-werkzeug.serving" title="Permalink to this headline">¶</a></h1>
<p>There are many ways to serve a WSGI application. While you’re developing it,
you usually don’t want to have a full-blown webserver like Apache up and
running, but instead a simple standalone one. Because of that Werkzeug comes
with a builtin development server.</p>
<p>The easiest way is creating a small <tt class="docutils literal"><span class="pre">start-myproject.py</span></tt> file that runs the
application using the builtin server:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python</span>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="kn">from</span> <span class="nn">werkzeug.serving</span> <span class="kn">import</span> <span class="n">run_simple</span>
<span class="kn">from</span> <span class="nn">myproject</span> <span class="kn">import</span> <span class="n">make_app</span>
<span class="n">app</span> <span class="o">=</span> <span class="n">make_app</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="n">run_simple</span><span class="p">(</span><span class="s">'localhost'</span><span class="p">,</span> <span class="mi">8080</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="n">use_reloader</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also pass it the <cite>extra_files</cite> keyword argument with a list of
additional files (like configuration files) you want to observe.</p>
<dl class="function">
<dt id="werkzeug.serving.run_simple">
<tt class="descclassname">werkzeug.serving.</tt><tt class="descname">run_simple</tt><big>(</big><em>hostname</em>, <em>port</em>, <em>application</em>, <em>use_reloader=False</em>, <em>use_debugger=False</em>, <em>use_evalex=True</em>, <em>extra_files=None</em>, <em>reloader_interval=1</em>, <em>reloader_type='auto'</em>, <em>threaded=False</em>, <em>processes=1</em>, <em>request_handler=None</em>, <em>static_files=None</em>, <em>passthrough_errors=False</em>, <em>ssl_context=None</em><big>)</big><a class="headerlink" href="#werkzeug.serving.run_simple" title="Permalink to this definition">¶</a></dt>
<dd><p>Start a WSGI application. Optional features include a reloader,
multithreading and fork support.</p>
<p>This function has a command-line interface too:</p>
<div class="highlight-python"><div class="highlight"><pre>python -m werkzeug.serving --help
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.5: </span><cite>static_files</cite> was added to simplify serving of static files as well
as <cite>passthrough_errors</cite>.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6: </span>support for SSL was added.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8: </span>Added support for automatically loading a SSL context from certificate
file and private key.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.9: </span>Added command-line interface.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.10: </span>Improved the reloader and added support for changing the backend
through the <cite>reloader_type</cite> parameter. See <a class="reference internal" href="#reloader"><em>Reloader</em></a>
for more information.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>hostname</strong> – The host for the application. eg: <tt class="docutils literal"><span class="pre">'localhost'</span></tt></li>
<li><strong>port</strong> – The port for the server. eg: <tt class="docutils literal"><span class="pre">8080</span></tt></li>
<li><strong>application</strong> – the WSGI application to execute</li>
<li><strong>use_reloader</strong> – should the server automatically restart the python
process if modules were changed?</li>
<li><strong>use_debugger</strong> – should the werkzeug debugging system be used?</li>
<li><strong>use_evalex</strong> – should the exception evaluation feature be enabled?</li>
<li><strong>extra_files</strong> – a list of files the reloader should watch
additionally to the modules. For example configuration
files.</li>
<li><strong>reloader_interval</strong> – the interval for the reloader in seconds.</li>
<li><strong>reloader_type</strong> – the type of reloader to use. The default is
auto detection. Valid values are <tt class="docutils literal"><span class="pre">'stat'</span></tt> and
<tt class="docutils literal"><span class="pre">'watchdog'</span></tt>. See <a class="reference internal" href="#reloader"><em>Reloader</em></a> for more
information.</li>
<li><strong>threaded</strong> – should the process handle each request in a separate
thread?</li>
<li><strong>processes</strong> – if greater than 1 then handle each request in a new process
up to this maximum number of concurrent processes.</li>
<li><strong>request_handler</strong> – optional parameter that can be used to replace
the default one. You can use this to replace it
with a different
<tt class="xref py py-class docutils literal"><span class="pre">BaseHTTPRequestHandler</span></tt>
subclass.</li>
<li><strong>static_files</strong> – a dict of paths for static files. This works exactly
like <tt class="xref py py-class docutils literal"><span class="pre">SharedDataMiddleware</span></tt>, it’s actually
just wrapping the application in that middleware before
serving.</li>
<li><strong>passthrough_errors</strong> – set this to <cite>True</cite> to disable the error catching.
This means that the server will die on errors but
it can be useful to hook debuggers in (pdb etc.)</li>
<li><strong>ssl_context</strong> – an SSL context for the connection. Either an
<tt class="xref py py-class docutils literal"><span class="pre">ssl.SSLContext</span></tt>, a tuple in the form
<tt class="docutils literal"><span class="pre">(cert_file,</span> <span class="pre">pkey_file)</span></tt>, the string <tt class="docutils literal"><span class="pre">'adhoc'</span></tt> if
the server should automatically create one, or <tt class="docutils literal"><span class="pre">None</span></tt>
to disable SSL (which is the default).</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="werkzeug.serving.is_running_from_reloader">
<tt class="descclassname">werkzeug.serving.</tt><tt class="descname">is_running_from_reloader</tt><big>(</big><big>)</big><a class="headerlink" href="#werkzeug.serving.is_running_from_reloader" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the application is running from within the Werkzeug
reloader subprocess.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.10.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="werkzeug.serving.make_ssl_devcert">
<tt class="descclassname">werkzeug.serving.</tt><tt class="descname">make_ssl_devcert</tt><big>(</big><em>base_path</em>, <em>host=None</em>, <em>cn=None</em><big>)</big><a class="headerlink" href="#werkzeug.serving.make_ssl_devcert" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an SSL key for development. This should be used instead of
the <tt class="docutils literal"><span class="pre">'adhoc'</span></tt> key which generates a new cert on each server start.
It accepts a path for where it should store the key and cert and
either a host or CN. If a host is given it will use the CN
<tt class="docutils literal"><span class="pre">*.host/CN=host</span></tt>.</p>
<p>For more information see <a class="reference internal" href="#werkzeug.serving.run_simple" title="werkzeug.serving.run_simple"><tt class="xref py py-func docutils literal"><span class="pre">run_simple()</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.9.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>base_path</strong> – the path to the certificate and key. The extension
<tt class="docutils literal"><span class="pre">.crt</span></tt> is added for the certificate, <tt class="docutils literal"><span class="pre">.key</span></tt> is
added for the key.</li>
<li><strong>host</strong> – the name of the host. This can be used as an alternative
for the <cite>cn</cite>.</li>
<li><strong>cn</strong> – the <cite>CN</cite> to use.</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<div class="admonition-information admonition">
<p class="first admonition-title">Information</p>
<p class="last">The development server is not intended to be used on production systems.
It was designed especially for development purposes and performs poorly
under high load. For deployment setups have a look at the
<a class="reference internal" href="deployment/index.html#deployment"><em>Application Deployment</em></a> pages.</p>
</div>
<div class="section" id="reloader">
<span id="id1"></span><h2>Reloader<a class="headerlink" href="#reloader" title="Permalink to this headline">¶</a></h2>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.10.</span></p>
</div>
<p>The Werkzeug reloader constantly monitors modules and paths of your web
application, and restarts the server if any of the observed files change.</p>
<p>Since version 0.10, there are two backends the reloader supports: <tt class="docutils literal"><span class="pre">stat</span></tt> and
<tt class="docutils literal"><span class="pre">watchdog</span></tt>.</p>
<ul class="simple">
<li>The default <tt class="docutils literal"><span class="pre">stat</span></tt> backend simply checks the <tt class="docutils literal"><span class="pre">mtime</span></tt> of all files in a
regular interval. This is sufficient for most cases, however, it is known to
drain a laptop’s battery.</li>
<li>The <tt class="docutils literal"><span class="pre">watchdog</span></tt> backend uses filesystem events, and is much faster than
<tt class="docutils literal"><span class="pre">stat</span></tt>. It requires the <a class="reference external" href="https://pypi.python.org/pypi/watchdog">watchdog</a>
module to be installed.</li>
</ul>
<p>If <tt class="docutils literal"><span class="pre">watchdog</span></tt> is installed and available it will automatically be used
instead of the builtin <tt class="docutils literal"><span class="pre">stat</span></tt> reloader.</p>
<p>To switch between the backends you can use the <cite>reloader_type</cite> parameter of the
<a class="reference internal" href="#werkzeug.serving.run_simple" title="werkzeug.serving.run_simple"><tt class="xref py py-func docutils literal"><span class="pre">run_simple()</span></tt></a> function. <tt class="docutils literal"><span class="pre">'stat'</span></tt> sets it to the default stat based
polling and <tt class="docutils literal"><span class="pre">'watchdog'</span></tt> forces it to the watchdog backend.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Some edge cases, like modules that failed to import correctly, are not
handled by the stat reloader for performance reasons. The watchdog reloader
monitors such files too.</p>
</div>
</div>
<div class="section" id="virtual-hosts">
<h2>Virtual Hosts<a class="headerlink" href="#virtual-hosts" title="Permalink to this headline">¶</a></h2>
<p>Many web applications utilize multiple subdomains. This can be a bit tricky
to simulate locally. Fortunately there is the <a class="reference external" href="http://en.wikipedia.org/wiki/Hosts_file">hosts file</a> that can be used
to assign the local computer multiple names.</p>
<p>This allows you to call your local computer <cite>yourapplication.local</cite> and
<cite>api.yourapplication.local</cite> (or anything else) in addition to <cite>localhost</cite>.</p>
<p>You can find the hosts file on the following location:</p>
<blockquote>
<div><table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="75%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Windows</td>
<td><tt class="docutils literal"><span class="pre">%SystemRoot%\system32\drivers\etc\hosts</span></tt></td>
</tr>
<tr class="row-even"><td>Linux / OS X</td>
<td><tt class="docutils literal"><span class="pre">/etc/hosts</span></tt></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>You can open the file with your favorite text editor and add a new name after
<cite>localhost</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre>127.0.0.1 localhost yourapplication.local api.yourapplication.local
</pre></div>
</div>
<p>Save the changes and after a while you should be able to access the
development server on these host names as well. You can use the
<a class="reference internal" href="routing.html#routing"><em>URL Routing</em></a> system to dispatch between different hosts or parse
<tt class="xref py py-attr docutils literal"><span class="pre">request.host</span></tt> yourself.</p>
</div>
<div class="section" id="shutting-down-the-server">
<h2>Shutting Down The Server<a class="headerlink" href="#shutting-down-the-server" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.</span></p>
</div>
<p>Starting with Werkzeug 0.7 the development server provides a way to shut
down the server after a request. This currently only works with Python
2.6 and later and will only work with the development server. To initiate
the shutdown you have to call a function named
<tt class="docutils literal"><span class="pre">'werkzeug.server.shutdown'</span></tt> in the WSGI environment:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">shutdown_server</span><span class="p">(</span><span class="n">environ</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="s">'werkzeug.server.shutdown'</span> <span class="ow">in</span> <span class="n">environ</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s">'Not running the development server'</span><span class="p">)</span>
<span class="n">environ</span><span class="p">[</span><span class="s">'werkzeug.server.shutdown'</span><span class="p">]()</span>
</pre></div>
</div>
</div>
<div class="section" id="troubleshooting">
<h2>Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h2>
<p>On operating systems that support ipv6 and have it configured such as modern
Linux systems, OS X 10.4 or higher as well as Windows Vista some browsers can
be painfully slow if accessing your local server. The reason for this is that
sometimes “localhost” is configured to be available on both ipv4 and ipv6 socktes
and some browsers will try to access ipv6 first and then ivp4.</p>
<p>At the current time the integrated webserver does not support ipv6 and ipv4 at
the same time and for better portability ipv4 is the default.</p>
<p>If you notice that the web browser takes ages to load the page there are two ways
around this issue. If you don’t need ipv6 support you can disable the ipv6 entry
in the <a class="reference external" href="http://en.wikipedia.org/wiki/Hosts_file">hosts file</a> by removing this line:</p>
<div class="highlight-python"><div class="highlight"><pre>::1 localhost
</pre></div>
</div>
<p>Alternatively you can also disable ipv6 support in your browser. For example
if Firefox shows this behavior you can disable it by going to <tt class="docutils literal"><span class="pre">about:config</span></tt>
and disabling the <cite>network.dns.disableIPv6</cite> key. This however is not
recommended as of Werkzeug 0.6.1!</p>
<p>Starting with Werkzeug 0.6.1, the server will now switch between ipv4 and
ipv6 based on your operating system’s configuration. This means if that
you disabled ipv6 support in your browser but your operating system is
preferring ipv6, you will be unable to connect to your server. In that
situation, you can either remove the localhost entry for <tt class="docutils literal"><span class="pre">::1</span></tt> or
explicitly bind the hostname to an ipv4 address (<cite>127.0.0.1</cite>)</p>
</div>
<div class="section" id="ssl">
<h2>SSL<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.</span></p>
</div>
<p>The builtin server supports SSL for testing purposes. If an SSL context is
provided it will be used. That means a server can either run in HTTP or HTTPS
mode, but not both.</p>
<div class="section" id="quickstart">
<h3>Quickstart<a class="headerlink" href="#quickstart" title="Permalink to this headline">¶</a></h3>
<p>The easiest way to do SSL based development with Werkzeug is by using it
to generate an SSL certificate and private key and storing that somewhere
and to then put it there. For the certificate you need to provide the
name of your server on generation or a <cite>CN</cite>.</p>
<ol class="arabic">
<li><p class="first">Generate an SSL key and store it somewhere:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">werkzeug.serving</span> <span class="kn">import</span> <span class="n">make_ssl_devcert</span>
<span class="gp">>>> </span><span class="n">make_ssl_devcert</span><span class="p">(</span><span class="s">'/path/to/the/key'</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="s">'localhost'</span><span class="p">)</span>
<span class="go">('/path/to/the/key.crt', '/path/to/the/key.key')</span>
</pre></div>
</div>
</li>
<li><p class="first">Now this tuple can be passed as <tt class="docutils literal"><span class="pre">ssl_context</span></tt> to the
<a class="reference internal" href="#werkzeug.serving.run_simple" title="werkzeug.serving.run_simple"><tt class="xref py py-func docutils literal"><span class="pre">run_simple()</span></tt></a> method:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">run_simple</span><span class="p">(</span><span class="s">'localhost'</span><span class="p">,</span> <span class="mi">4000</span><span class="p">,</span> <span class="n">application</span><span class="p">,</span>
<span class="n">ssl_context</span><span class="o">=</span><span class="p">(</span><span class="s">'/path/to/the/key.crt'</span><span class="p">,</span>
<span class="s">'/path/to/the/key.key'</span><span class="p">))</span>
</pre></div>
</div>
</li>
</ol>
<p>You will have to acknowledge the certificate in your browser once then.</p>
</div>
<div class="section" id="loading-contexts-by-hand">
<h3>Loading Contexts by Hand<a class="headerlink" href="#loading-contexts-by-hand" title="Permalink to this headline">¶</a></h3>
<p>In Python 2.7.9 and 3+ you also have the option to use a <tt class="docutils literal"><span class="pre">ssl.SSLContext</span></tt>
object instead of a simple tuple. This way you have better control over the SSL
behavior of Werkzeug’s builtin server:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">ssl</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">SSLContext</span><span class="p">(</span><span class="n">ssl</span><span class="o">.</span><span class="n">PROTOCOL_SSLv23</span><span class="p">)</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">load_cert_chain</span><span class="p">(</span><span class="s">'ssl.cert'</span><span class="p">,</span> <span class="s">'ssl.key'</span><span class="p">)</span>
<span class="n">run_simple</span><span class="p">(</span><span class="s">'localhost'</span><span class="p">,</span> <span class="mi">4000</span><span class="p">,</span> <span class="n">application</span><span class="p">,</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ctx</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="generating-certificates">
<h3>Generating Certificates<a class="headerlink" href="#generating-certificates" title="Permalink to this headline">¶</a></h3>
<p>A key and certificate can be created in advance using the openssl tool
instead of the <a class="reference internal" href="#werkzeug.serving.make_ssl_devcert" title="werkzeug.serving.make_ssl_devcert"><tt class="xref py py-func docutils literal"><span class="pre">make_ssl_devcert()</span></tt></a>. This requires that you have
the <cite>openssl</cite> command installed on your system:</p>
<div class="highlight-python"><div class="highlight"><pre>$ openssl genrsa 1024 > ssl.key
$ openssl req -new -x509 -nodes -sha1 -days 365 -key ssl.key > ssl.cert
</pre></div>
</div>
</div>
<div class="section" id="adhoc-certificates">
<h3>Adhoc Certificates<a class="headerlink" href="#adhoc-certificates" title="Permalink to this headline">¶</a></h3>
<p>The easiest way to enable SSL is to start the server in adhoc-mode. In
that case Werkzeug will generate an SSL certificate for you:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">run_simple</span><span class="p">(</span><span class="s">'localhost'</span><span class="p">,</span> <span class="mi">4000</span><span class="p">,</span> <span class="n">application</span><span class="p">,</span>
<span class="n">ssl_context</span><span class="o">=</span><span class="s">'adhoc'</span><span class="p">)</span>
</pre></div>
</div>
<p>The downside of this of course is that you will have to acknowledge the
certificate each time the server is reloaded. Adhoc certificates are
discouraged because modern browsers do a bad job at supporting them for
security reasons.</p>
<p>This feature requires the pyOpenSSL library to be installed.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper"><p class="logo"><a href="index.html">
<img class="logo" src="_static/werkzeug.png" alt="Logo"/>
</a></p>
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Serving WSGI Applications</a><ul>
<li><a class="reference internal" href="#reloader">Reloader</a></li>
<li><a class="reference internal" href="#virtual-hosts">Virtual Hosts</a></li>
<li><a class="reference internal" href="#shutting-down-the-server">Shutting Down The Server</a></li>
<li><a class="reference internal" href="#troubleshooting">Troubleshooting</a></li>
<li><a class="reference internal" href="#ssl">SSL</a><ul>
<li><a class="reference internal" href="#quickstart">Quickstart</a></li>
<li><a class="reference internal" href="#loading-contexts-by-hand">Loading Contexts by Hand</a></li>
<li><a class="reference internal" href="#generating-certificates">Generating Certificates</a></li>
<li><a class="reference internal" href="#adhoc-certificates">Adhoc Certificates</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="python3.html" title="previous chapter">Python 3 Notes</a></li>
<li>Next: <a href="test.html" title="next chapter">Test Utilities</a></li>
</ul></li>
</ul>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/serving.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2011, The Werkzeug Team.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
</div>
</body>
</html>
|