Huett
Huett

Reputation: 1

How to get multiple choices from template in views.py

In my template i have a multiple-choice-object like this:

<form action="/hmi/give_trend3/" method="get">
    <p>
        <select name="n" size="3" multiple="multiple">
        {% for tag in tags %}
            <option>{{ tag.name }}</option><br>
        {% endfor %}
        </select>
    </p>
</form>

and i want to get all the values (of the multiple-choice) in my views.py:

def give_trend3(request):
    v = request.GET['v']
    b = request.GET['b']
    nn = request.GET['n'] ....

but in the value nn I find only the last value of the choices.

How do I do that?

Upvotes: 0

Views: 1078

Answers (1)

Neerajlal K
Neerajlal K

Reputation: 6828

Try this,

vals = request.GET.getlist("n", '')

Also bind the id to the options in your template,

<select name="n" size="3" multiple="multiple">
{% for tag in tags %}
    <option value="{{ tag.id }}">{{ tag.name }}</option><br>
{% endfor %}
</select>

Upvotes: 2

Related Questions