module-cgihttpserver.html
来自「一本很好的python的说明书,适合对python感兴趣的人」· HTML 代码 · 共 150 行
HTML
150 行
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.16 CGIHTTPServer -- CGI-capable HTTP request handler</title>
<META NAME="description" CONTENT="11.16 CGIHTTPServer -- CGI-capable HTTP request handler">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html">
<LINK REL="previous" href="module-SimpleHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html">
<LINK REL="up" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">
<LINK REL="next" href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-SimpleHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-SimpleHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html">11.15 SimpleHTTPServer </A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html">11.17 Cookie </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00131600000000000000000">
11.16 <tt class="module">CGIHTTPServer</tt> --
CGI-capable HTTP request handler</A>
</H1>
<P>
<p class='availability'>Availability: <span
class='platform'>Unix</span>.</p>
<P>
The <tt class="module">CGIHTTPServer</tt> module defines a request-handler class,
interface compatible with
<tt class="class">BaseHTTPServer.BaseHTTPRequestHandler</tt> and inherits behavior
from <tt class="class">SimpleHTTPServer.SimpleHTTPRequestHandler</tt> but can also
run CGI scripts.
<P>
<b>Note:</b> This module is Unix dependent since it creates the
CGI process using <tt class="function">os.fork()</tt> and <tt class="function">os.exec()</tt>.
<P>
The <tt class="module">CGIHTTPServer</tt> module defines the following class:
<P>
<dl><dt><b><a name='l2h-2265'><tt class='class'>CGIHTTPRequestHandler</tt></a></b> (<var>request, client_address, server</var>)
<dd>
This class is used to serve either files or output of CGI scripts from
the current directory and below. Note that mapping HTTP hierarchic
structure to local directory structure is exactly as in
<tt class="class">SimpleHTTPServer.SimpleHTTPRequestHandler</tt>.
<P>
The class will however, run the CGI script, instead of serving it as a
file, if it guesses it to be a CGI script. Only directory-based CGI
are used -- the other common server configuration is to treat special
extensions as denoting CGI scripts.
<P>
The <tt class="function">do_GET()</tt> and <tt class="function">do_HEAD()</tt> functions are
modified to run CGI scripts and serve the output, instead of serving
files, if the request leads to somewhere below the
<code>cgi_directories</code> path.
</dl>
<P>
The <tt class="class">CGIHTTPRequestHandler</tt> defines the following data member:
<P>
<dl><dt><b><a name='l2h-2266'><tt class='member'>cgi_directories</tt></a></b>
<dd>
This defaults to <code>['/cgi-bin', '/htbin']</code> and describes
directories to treat as containing CGI scripts.
</dl>
<P>
The <tt class="class">CGIHTTPRequestHandler</tt> defines the following methods:
<P>
<dl><dt><b><a name='l2h-2267'><tt class='method'>do_POST</tt></a></b> ()
<dd>
This method serves the <code>'POST'</code> request type, only allowed for
CGI scripts. Error 501, "Can only POST to CGI scripts", is output
when trying to POST to a non-CGI url.
</dl>
<P>
Note that CGI scripts will be run with UID of user nobody, for security
reasons. Problems with the CGI script will be translated to error 403.
<P>
For example usage, see the implementation of the <tt class="function">test()</tt>
function.
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-BaseHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-BaseHTTPServer.html">BaseHTTPServer</a></tt>:</b>
<dd>Base class implementation for Web server
and request handler.
</dl>
</div>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-SimpleHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-SimpleHTTPServer.html" tppabs="http://www.python.org/doc/current/lib/module-SimpleHTTPServer.html">11.15 SimpleHTTPServer </A>
<b class="navlabel">Up:</b> <a class="sectref" href="internet.html" tppabs="http://www.python.org/doc/current/lib/internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-Cookie.html" tppabs="http://www.python.org/doc/current/lib/module-Cookie.html">11.17 Cookie </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?