Home > Software engineering >  Django - Pass a dropdown Item value from the template to the view
Django - Pass a dropdown Item value from the template to the view

Time:02-10

I have a Django template that looks like this

<td>{{ row.column1 }}</td>
<td>{{ row.column2 }}</td>
<td>{{ row.column3 }}</td>
<td>
    <select name="dropdown_menu_option" id="dropdown_menu_option">
        <option selected="selected" disabled>--SELECT--</option>
        <option value="10">10</option>
        <option value="50">50</option>
        <option value="100">100</option>
        <option value="256">256</option>
        <option value="512">512</option>
        <option value="1">1</option>
    </select>
</td>
<td><a href="{% url 'exampleurl' row.column1 row.column2 row.column3 dropdown_menu_option %}" >Take Action</a></td>

I have my URLs set up like this -

url(r'exampleurl/(?P<column1>. )/(?P<column2>. )/(?P<column3>. )/(?P<dropdownvalue>)$', viewName, name='exampleurl'),

My view is set up like this -

def viewName(request, directory, column1, column2, column3, dropdownvalue):
    print(column1)
    print(column2)
    print(column3)
    print(dropdownvalue)

The problem I am having is, dropdownvalue is NULL. This is one of the reasons I have removed the regex from the URL.py file for dropdownvalue.

How do I pass this value from my template to the view?

CodePudding user response:

  •  Tags:  
  • Related