Reading user selection from Django 1.5 template without using Models
<p>Im using <strong>Python27</strong> with <strong>Django 1.5</strong>.</p>

<p>i have been scowering the internet for hours without success. Is there a way to capture what the user has selected from a dropdown listbox in a template without using Models? Im looking for a direct way to read some sort of var into code in views.py.</p>

<p><em>example.html</em></p>

<pre><code>&lt;select name="num_select"&gt;
    &lt;option value="0"&gt;-----&lt;/option&gt;
    &lt;option value="10"&gt;1 - 10&lt;/option&gt;
    &lt;option value="20"&gt;10 - 20&lt;/option&gt;
    &lt;option value="30"&gt;20 - 30&lt;/option&gt;
    &lt;option value="40"&gt;30 - 40&lt;/option&gt;
    &lt;option value="all"&gt;all&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>which every option i select I want to pass the value to a var in my views.py</p>

<p><em>views.py</em></p>

<pre><code>def my_view(request):
    ...
    num_select = forms.????.get['num_select']
    ...
    return blah blah....
</code></pre>

<p>I hope i have provided enough details for you to assist me. Not sure what else i can add. I have been going through pages of docs without success. I know how to get vars from views.py to html templates, but not vise-versa. </p>

<p>Help is greatly appreciated. </p>

<p>You can read raw form data by using <code>HttpRequest.POST</code> API</p>

<p><a href="https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.POST" rel="nofollow">https://docs.djangoproject.com/en/1.10/ref/request-response/#django.http.HttpRequest.POST</a></p>

<p>It's a dictionary-like object containing all given HTTP POST parameters.</p>

<p>You can just <code>request.POST['num_select']</code></p>

<p>Remember to include <code>if request.method == 'POST':</code> before using <code>request.POST</code></p>

python html django templates html-select