hakunami
hakunami

Reputation: 2441

What is the format when I get data from multiple checkboxs? Can I get a list?

I have a Kind Tag with property tagName, and in a html, I code like this

{% for tag in tags%}
    <input type="checkbox" name="tagName" value={{tag.tagName}}>{{tag.tagName}}
{% endfor%}

Now, In my python file, I try to do this:

tagNames = self.request.get('tagName')

I want a list that contain every choice user choose. But what I got seems not. So.

  1. how can I get a list of user choices using request.get()?

  2. Is there any other ways? I am not familiar with django, I just import gae's template. Can I use gae's template to simplify this question?

Thank you!

Upvotes: 2

Views: 123

Answers (2)

Wooble
Wooble

Reputation: 90007

Assuming you're using the webapp framework, instead of self.request.get(), use self.request.get_all('tagName'), which will return a list of values.

Upvotes: 2

lecstor
lecstor

Reputation: 5707

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict

Looks like QueryDict.getlist(key, default) will get you what you want.

ie. self.request.getlist('tagName')

Upvotes: 2

Related Questions