0

Есть такой кусок шаблона:

{% for item in items %}
    <form method="post" action="update">
    {% csrf_token %}
  ........................
          <select multiple = 'multiple' style='height: 100%;' name = 'subitems'>
                {% for subitem in item.5 %}
                     <option value="{{ subitem.0 }}" selected="True">{{ subitem.1 }}</option>
                {% endfor %}
            </select>
        </label><br>
        </p>
  <p><input type="submit" ></p>
    </form>
{% endfor %}

Во view читаю так:

if request.method == 'POST':
   ......................
    genres = request.POST.get('subitems')

В результате читает только последнее значение из subitems. Как прочитать все?

1 ответ 1

0

get берет только одно значение, нужно пользоваться getlist.

if request.method == 'POST':
   ......................
    genres = request.POST.getlist('subitems')

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.