1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<title>6.1.2.1 Traversal</title>
5
<META NAME="description" CONTENT="6.1.2.1 Traversal">
6
<META NAME="keywords" CONTENT="modpython">
7
<META NAME="resource-type" CONTENT="document">
8
<META NAME="distribution" CONTENT="global">
9
<link rel="STYLESHEET" href="modpython.css">
10
<link rel="first" href="modpython.html">
11
<link rel="contents" href="contents.html" title="Contents">
12
<link rel="index" href="genindex.html" title="Index">
13
<LINK REL="next" href="hand-pub-alg-args.html">
14
<LINK REL="previous" href="hand-pub-alg.html">
15
<LINK REL="up" href="hand-pub-alg.html">
16
<LINK REL="next" href="hand-pub-alg-args.html">
19
<DIV CLASS="navigation">
20
<table align="center" width="100%" cellpadding="0" cellspacing="2">
22
<td><A href="hand-pub-alg.html"><img src="icons/previous.gif"
23
border="0" height="32"
24
alt="Previous Page" width="32"></A></td>
25
<td><A href="hand-pub-alg.html"><img src="icons/up.gif"
26
border="0" height="32"
27
alt="Up One Level" width="32"></A></td>
28
<td><A href="hand-pub-alg-args.html"><img src="icons/next.gif"
29
border="0" height="32"
30
alt="Next Page" width="32"></A></td>
31
<td align="center" width="100%">Mod_python Manual</td>
32
<td><A href="contents.html"><img src="icons/contents.gif"
33
border="0" height="32"
34
alt="Contents" width="32"></A></td>
35
<td><img src="icons/blank.gif"
36
border="0" height="32"
37
alt="" width="32"></td>
38
<td><A href="genindex.html"><img src="icons/index.gif"
39
border="0" height="32"
40
alt="Index" width="32"></A></td>
42
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
43
<b class="navlabel">Up:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
44
<b class="navlabel">Next:</b> <a class="sectref" href="hand-pub-alg-args.html">6.1.2.2 Argument Matching and</A>
47
<!--End of Navigation Panel-->
49
<H3><A NAME="SECTION008121000000000000000"> </A>
55
The Publisher handler locates and imports the module specified in the
56
URI. The module location is determined from the <tt class="class">req.filename</tt>
57
attribute. Before importing, the file extension, if any, is
61
If <tt class="class">req.filename</tt> is empty, the module name defaults to
62
"<tt class="samp">index</tt>".
65
Once module is imported, the remaining part of the URI up to the
66
beginning of any query data (a.k.a. PATH_INFO) is used to find an
67
object within the module. The Publisher handler <i class="dfn">traverses</i> the
68
path, one element at a time from left to right, mapping the elements
69
to Python object within the module.
72
If no path_info was given in the URL, the Publisher handler will use
73
the default value of "<tt class="samp">index</tt>". If the last element is an object inside
74
a module, and the one immediately preceding it is a directory
75
(i.e. no module name is given), then the module name will also default
76
to "<tt class="samp">index</tt>".
79
The traversal will stop and <tt class="constant">HTTP_NOT_FOUND</tt> will be returned to
85
<LI>Any of the traversed object's names begin with an underscore
86
("<tt class="samp">_</tt>"). Use underscores to protect objects that should not be
87
accessible from the web.
91
<LI>A module is encountered. Published objects cannot be modules for
99
If an object in the path could not be found, <tt class="constant">HTTP_NOT_FOUND</tt>
100
is returned to the client.
103
For example, given the following configuration:
106
<dl><dd><pre class="verbatim">
107
DocumentRoot /some/dir
109
<Directory /some/dir>
110
SetHandler mod_python
111
PythonHandler mod_python.publisher
116
And the following <span class="file">/some/dir/index.py</span> file:
119
<dl><dd><pre class="verbatim">
122
return "We are in index()"
126
return "We are in hello()"
133
http://www.somehost/index/index will return "<tt class="samp">We are in index()</tt>"
135
http://www.somehost/index/ will return "<tt class="samp">We are in index()</tt>"
137
http://www.somehost/index/hello will return "<tt class="samp">We are in hello()</tt>"
139
http://www.somehost/hello will return "<tt class="samp">We are in hello()</tt>"
141
http://www.somehost/spam will return "<tt class="samp">404 Not Found</tt>"
144
<DIV CLASS="navigation">
146
<table align="center" width="100%" cellpadding="0" cellspacing="2">
148
<td><A href="hand-pub-alg.html"><img src="icons/previous.gif"
149
border="0" height="32"
150
alt="Previous Page" width="32"></A></td>
151
<td><A href="hand-pub-alg.html"><img src="icons/up.gif"
152
border="0" height="32"
153
alt="Up One Level" width="32"></A></td>
154
<td><A href="hand-pub-alg-args.html"><img src="icons/next.gif"
155
border="0" height="32"
156
alt="Next Page" width="32"></A></td>
157
<td align="center" width="100%">Mod_python Manual</td>
158
<td><A href="contents.html"><img src="icons/contents.gif"
159
border="0" height="32"
160
alt="Contents" width="32"></A></td>
161
<td><img src="icons/blank.gif"
162
border="0" height="32"
163
alt="" width="32"></td>
164
<td><A href="genindex.html"><img src="icons/index.gif"
165
border="0" height="32"
166
alt="Index" width="32"></A></td>
168
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
169
<b class="navlabel">Up:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
170
<b class="navlabel">Next:</b> <a class="sectref" href="hand-pub-alg-args.html">6.1.2.2 Argument Matching and</A>
172
<span class="release-info">Release 3.1.3, documentation updated on February 17, 2004.</span>
174
<!--End of Navigation Panel-->