Search code examples
pythonformswerkzeug

self.request.form not iterable?


Hello I am making a form in HTML and python and I am having a problem with processing the arguments

the problem comes in this section

<form method="POST">
  <input type="checkbox" name="brands" value="1" />
  <input type="checkbox" name="brands" value="2" />
</form>

and in the python I am using a self.request.form object to retrieve the arguments the problem is if I do something like

for b in brands:
   print b

it will just print out 1 even if both of them are in the self.request.form object

USING Werkzeug Framework

ANSWERED: I found you can retrieve a list of the same named inputs using this syntax

self.request.form.getlist('brands')

Solution

  • I found you can retrieve a list of the same named inputs using this syntax

    self.request.form.getlist('brands')