Reputation: 45
I am trying to DRY up my webapp2.RequestHandlers by moving POST variable fetching and validation out to a Function.
self.request.get doesnt work in the Function outside of the Handler. How do I access the POST vars from a Function?
class my_form(webapp2.RequestHandler):
def post(self):
fieldvalidation('field1', 'string')
def fieldvalidation(fieldname, validationoptions):
x = self.request.get(fieldname) # <<< does not work outside of class my_form
.......
Upvotes: 0
Views: 4849
Reputation: 11706
You have to pass self or self.request to the function.
class my_form(webapp2.RequestHandler):
def post(self):
fieldvalidation(self.request)
def fieldvalidation(request):
x = request.get(fieldname) # <<< get the fieldname from the request object
Upvotes: 1