Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Quetion about post fields #325

Closed
wsantos opened this Issue · 2 comments

2 participants

@wsantos

Why fields are in list in a post ?

(Pdb++) self.request.arguments
{'name': ['Cadaf'], 'email': ['Cadaf@cadaf.com']}

any reason for this ? thnx.

@jehiah

typically you don't access self.request.arguments directly but via self.get_argument() and self.get_arguments() docs

it's by design that it's a list so that the data type doesn't change between having one argument for that key, and multiple.

@wsantos

Thnx for the quick response, i got it. Btw i will register a simple way to use the post fields with wtform for future reference.

from wtforms import Form, TextField, validators

class TestForm(Form):
    field1     = TextField('field1', [validators.Length(min=4, max=25)])
    field2    = TextField('field2', [validators.Length(min=6, max=35)])


class HomeHandler(BaseHandler):

    def get(self):
        self.render('home.html')

    def post(self):
        form = TestForm(**dict([(key,self.get_argument(key)) for key in self.request.arguments]))
        validated = form.validate()

        self.write('Valid form: %r' % (validated))
@wsantos wsantos closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.