-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfaq.txt
49 lines (40 loc) · 1.39 KB
/
faq.txt
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
= FAQ =
== Modules ==
=== When loading a Nevow application using built-in Twisted server via 'twistd -noy file.tac', why do I get an import error when importing my module 'foo'? ===
Twisted does not recognize the current directory as loaded in Python path. On your file.tac, before any nevow or twisted modules are imported do this :
{{{
#!python
# file.tac
import os, sys
sys.path.append(os.getcwd()) # loads the current directory to Python path
# then start loading nevow and twisted modules
from twisted.application import service, internet
# start importing your modules here
from foo import BarPage
# etc...
-----------------------
# foo.BarPage.py
from nevow.rend import Page
class BarPage( Page ):
def renderHTTP( self, ctx ):
return 'foo'
}}}
== Request parameters ==
=== How do I extract request parameters ===
Request parameters come from the context object (but beware this: ).
You adapt the context object to an IRequest object. The parameters are stored in the args dictionary.
{{{
#!python
request = inevow.IRequest(ctx)
if request.args.has_key('myparam'):
validate(request.args['myparam'])
}}}
== Testing ==
=== How do I make fake context objects? ===
Divmod contains a testutil module that contains a set of ready made classes like !FakeRequest, !FakeSession etc. Use these.
Example:
{{{
#!python
ctx = context.WebContext(tag=page)
ctx.remember(testutil.AccumulatingFakeRequest())
}}}