0

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 %}" class="action-button-small shadow animate grey">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?

Swaminathan K
  • 37
  • 1
  • 8
  • You can get the selected value using JavaScript like shown [here](https://stackoverflow.com/a/59968055/10951070) if you really want to send this in the url as a get request, but I would suggest this be sent as a POST request within a form, as shown [here](https://stackoverflow.com/a/11586830/10951070). – raphael Feb 09 '22 at 20:40
  • Hey, thank you for the comment. I did see the POST form option before posting the question. However, that would add a "Select" button to my cell and I guess I have to create a new form? – Swaminathan K Feb 09 '22 at 20:53
  • Yes, you need to add a form, but NO, this will NOT add a submit button, nor the form tags, those you have to do in your html. Checkout the [docs](https://docs.djangoproject.com/en/4.0/topics/forms/). – raphael Feb 09 '22 at 22:27

0 Answers0