I’ve seen a couple of documents on how to collect the data from a HTML statement in Django but none of them were very clear to me. Does anybody have a real working example to share?
In my case I have something like this in my template file:
<select title="my_options">
<option value="1">Select value 1</option>
<option value="2">Select value 2</option>
</select>
What goes in the views.py in order to collect the selected value? Thank you!
If it’s a GET request,
request.GET['my_options']. If it’s a POST, thenrequest.POST['my_options']. This will be a string, either"1"or"2"(or"<script>alert('I hacked you!')</script>")Either way, it’s probably better to use the Django forms framework to save you the hassle of writing the HTML, and sanitizing the returned values.