0

I have a html form that looks like this.

{% url 'myapp:myapp_submit' as submit %}

<form name='main' method="POST" action={{submit}}> 
{% csrf_token %}
<select class='form-control' size=10 id="test" name='test' multiple>
<option>Test</option>
</select>
<input type="submit"/>
</form>

and url.py

from . import views

    app_name = 'myapp'
    urlpatterns = [
        url(r'^$', views.myapp, name='myapp'),
        url(r'results/$', views.myapp_submit, name='myapp_submit')
    ]

and views.py

def myapp_submit(request):
    print request.POST

The only thing I get back is

<QueryDict: {u'csrfmiddlewaretoken'...]}>

How do I get back the options held in the select tag? I would use the model/view form here but I'm doing some very crazy things with JS to constantly update the options available.

UPDATE

I have used:

request.POST.getlist('test')

But it will only return ['Test'] If I highlight it with my mouse. I simply want all the options under the select tag. ex.

<select class='form-control' size=10 id="test" name='test' multiple>
<option>Test1</option>
<option>Test2</option>
<option>Test3</option>
<option>Test4</option>
</select>

and

###Not sure if it's still getlist method
>>request.POST.getlist('test')
['Test','Test2','Test3','Test4']
jwillis0720
  • 3,846
  • 8
  • 37
  • 66
  • Possible duplicate of [Django: using – Sevanteri Aug 29 '16 at 07:38
  • see http://stackoverflow.com/questions/39217259/django-get-unused-all-options-in-a-select-tag where I cleared this up. Sorry for the double post – jwillis0720 Aug 30 '16 at 00:49

2 Answers2

1

Try to change your views.py:

def myapp_submit(request):
    request.POST.getlist('test[]')
gofr1
  • 15,444
  • 11
  • 42
  • 49
SumanKalyan
  • 1,491
  • 12
  • 23
0

Because you say you're doing weird things with Js, you can first check the POST request from your browser and what parameters you send with it.

Jai Kumar Rajput
  • 3,555
  • 2
  • 34
  • 52
Kostas
  • 51
  • 5