Pyramid flags

I'm just new to python and pyramid, and I'm afraid how to handle the results of a form containing multiple checkboxes in Pyramid.

Here is an excerpt from my form:

<p tal:repeat="category categories"> <input type="checkbox" name="selectedcategories" value="${category.id}"> ${category.name}<br/> </p> 

And this is how I am now trying to iterate and process the results:

 selectedcategories=request.params['selectedcategories'] for categoryid in selectedcategories: category = DBSession.query(Category).filter_by(id=categoryid).one() article.categories.append(category) 

As you might have guessed, I get a maximum of one checkbox, regardless of how much I choose on the form. Django has the ability to return results as a list, but I cannot figure out how to do this with Pyramid.

+6
source share
1 answer

request.params is multidict . To get multiple values, you can call the getall () method:

 selectedcategories = request.params.getall("selectedcategories") 
+6
source

Source: https://habr.com/ru/post/922110/


All Articles