[Twisted-web] How works formless?
Donovan Preston
dp at ulaluma.com
Thu Jun 30 10:30:40 MDT 2005
On Jun 30, 2005, at 2:58 AM, Alberto Trujillo wrote:
> Hello:
> I was trying to follow this example but I'm a bit lost. I can see
> the form but when I submit the information I receive the next
> exepction error "global name request is not defined".
> I don't know why formless has to be autocallable and where I must
> to defined "request"
>
> Could anybody help me? Here are my files. I need to know what I
> have to do after submit the information.
If you are just starting with Nevow, I suggest staying away from
formless for a while. It is designed for a very specific use case,
and has some well-known problems which nobody has taken the time to fix.
> year.tac
> ----------
> from twisted.application import internet, service
> from nevow import appserver
> import year
>
> application = service.Application("tasks")
> webserver = internet.TCPServer(8080, appserver.NevowSite
> (year.Colorful()))
> webserver.setServiceParent(application)
>
> year.py
> ---------
> from nevow import rend, loaders
> import formless
>
> class YearChooseable(formless.TypedInterface):
> def selectYear(self, year=formless.Integer()):
> pass
> selectYear = formless.autocallable(selectYear)
>
>
> class Colorful(rend.Page):
> __implements__ = YearChooseable, rend.Page.__implements__
>
>
> def selectYear(self, year):
> self.test = True
> return rend.Page.locateChild(self, request, childSegments)
This line is very strange. autocallables don't normally return
things, they normally just change object state. self.test = True is
correct, but the line below it looks like it comes from an overridden
locateChild method, which is totally inappropriate for a formless
autocallable. Also, I don't think locateChild has ever taken a
request argument; it has always taken a context argument. Remove this
line and everything should work fine.
> docFactory = loaders.xmlfile("year.html")
>
> year.html
> ----------
> <form action="freeform_post!!selectYear" method="POST">
> Type a year: <input type="text" name="year" />
> <input type="submit" />
> </form>
Donovan
More information about the Twisted-web
mailing list