我有一个html表单,看起来像这样。在
{% 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>
和网址.py
^{pr2}$和视图.py
def myapp_submit(request):
print request.POST
我唯一能回来的就是
<QueryDict: {u'csrfmiddlewaretoken'...]}>
如何取回select标记中的选项?我会在这里使用model/view表单,但是我用JS做了一些非常疯狂的事情来不断更新可用的选项。在
更新
我用过:
request.POST.getlist('test')
但只有当我用鼠标高亮显示它时,它才会返回['Test']。我只需要select标签下的所有选项。例如
<select class='form-control' size=10 id="test" name='test' multiple>
<option>Test1</option>
<option>Test2</option>
<option>Test3</option>
<option>Test4</option>
</select>
以及
###Not sure if it's still getlist method
>>request.POST.getlist('test')
['Test','Test2','Test3','Test4']
因为您说您正在使用Js执行奇怪的操作,所以您可以首先检查来自浏览器的
POST
请求以及随它发送的参数。在尝试更改您的
views.py
:相关问题 更多 >
编程相关推荐