[Twisted-web] fragments with child lookup
markus at bluegap.ch
Sat Sep 23 07:52:25 CDT 2006
I've now had a look at your source code:
Valentino Volonghi aka Dialtone wrote:
> http://hg.stiq.it/stiq for some more code.
I've learned about nevow macros. I don't quite understand what the big
difference to a renderer is, but that's another story...
I'm still trying to get my 'component' based thinking migrated to nevow.
As an exercise, I thought I'd try to use the nevow example pastebin as a
component. What I want to achieve is having the pastebin available under
http://localhost:8080/pastebin/, wrapped within my own template.
http://localhost:8080/ should simply show a welcome page, within the
For this experiment, I've simply stuffed a SuperiorRootPage class into
pastebin.tac. The simplistic template is included as stan. The pastebin
should be rendered inside that (so, my 'hello world' title would appear
on top). Of course, the main pastebin template (templates/site.html)
would need to be adjusted. But not the python code.
I don't know if I should think of the included pastebin as a Fragment?
Certainly it's a Page, as it is.
Bellow is what I've tried. I still don't know how to make such a thing
work. Somebody care to enlighten me?
--- pastebin.tac (revision 9132)
+++ pastebin.tac (working copy)
@@ -5,6 +5,7 @@
from nevow import appserver
from nevow import vhost
+from nevow import inevow, rend, stan, loaders, tags as T
from pastebin import interfaces
from pastebin.service import FSPasteBinService
@@ -16,7 +17,31 @@
pastebin = FSPasteBinService('data')
-appResource = pages.RootPage(pastebin)
+ addSlash = True
+ docFactory = loaders.stan(
+ T.h1['hello world'],
+ def locateChild(self, ctx, segments):
+ self.remaining_segments = segments[1:]
+ return self, ()
+ child_pastebin = pages.RootPage(pastebin)
+ def macro_content(self, ctx):
+ print "remaining_segments: %s" % str(self.remaining_segments)
+ if len(self.remaining_segments) == 0:
+ return "welcome!"
+ # what to return here???
+ return "duh!"
+appResource = SuperiorRootPage(pastebin)
vResource = vhost.VHostMonsterResource()
More information about the Twisted-web