How to pass values of drop down from html template to views in Django?

603 views
Skip to first unread message

ratnadeep ray

unread,
Jun 26, 2020, 9:52:16 AM6/26/20
to Django users

I need to send the value of the selected option in a drop down to the views.

My html code is as follows:

<select name="version" id="version" onchange="location = this.value;">
<option>Select version to compare with</option>
{%for ver in version_list%}
**<option value={{ver}} href="{% url 'process_data' ver %}">{{ver}}</option>**
{% endfor %}
</select>


The above is giving me the following error:

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/index/11.5.1.18900-96
http://127.0.0.1:8000/index/11.5.1.18900-97
Using the URLconf defined in Piechart_Excel.urls, Django tried these URL patterns, in this order:
admin/
index/
process_data/<str:ver> [name='process_data']
The current path, index/11.5.1.18900-96, didn't match any of these.


However if I am sending the value as follows i.e. without any drop down:

<a href="{% url 'process_data' ver1 %}">{{ver}}</a>


everything is working as expected.


My urls.py file content is as follows:


from django.urls import path
from fusioncharts import views urlpatterns
urlpatterns = [
path('index/', views.index, name='index'),
path('process_data/<str:ver>', views.process_data, name='process_data'),
]

Can anyone say why is it not working in the case of drop down but working otherwise? If we have to send any value from the html template using drop down, then how to do so?

Thanks.

Reply all
Reply to author
Forward
0 new messages