[Twisted-web] looking for a request.getfirst
Andy Gayton
andy at thecablelounge.com
Mon Oct 17 06:01:10 MDT 2005
Michele Simionato wrote:
> I am surprise I don't find a method to extract the value of a field from a
> request object. At the moment I am using a helper function
>
> def getfirst(name, request):
> return request.args.get(name, [None])[0]
>
> but is there a better solution?
There is a convenience method 'arg' on nevow's context object that does
this:
def arg(self, get, default=None):
"""Placeholder until I can find Jerub's implementation of this
Return a single named argument from the request arguments
"""
req = self.locate(IRequest)
return req.args.get(get, [default])[0]
It's used in nevow/examples/manualform
HTH,
Andy.
More information about the Twisted-web
mailing list