1

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
  • 4,329
  • 8
  • 41
  • 74
  • 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

3 Answers3

1

Try to change your views.py:

def myapp_submit(request):
    request.POST.getlist('test[]')
gofr1
  • 15,741
  • 11
  • 42
  • 52
SumanKalyan
  • 1,681
  • 14
  • 24
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 Chauhan
  • 4,035
  • 3
  • 36
  • 62
Kostas
  • 51
  • 5
0

A month ago I solved this problem, you need to use name in your option tag

Example:

<select name="status">
<option name="status">

and see result in your view.

Muhammadalive
  • 648
  • 5
  • 5