0

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?

Ivan Semochkin
  • 8,649
  • 3
  • 43
  • 75
Huett
  • 1
  • 1
  • possible duplicate of [Handling Django request.GET and multiple variables for the same parameter name](http://stackoverflow.com/questions/3910165/handling-django-request-get-and-multiple-variables-for-the-same-parameter-name) – Daniel Roseman Feb 03 '15 at 12:46

1 Answers1

2

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>
K Neeraj Lal
  • 6,768
  • 3
  • 24
  • 33