Passing the value of selected option of dropdown value to django database

I am working on a Django project. I am making an HTML form (not using the Djnango forms). Now, I am able to pass the values of “text” inputs to the database using the “POST” method (just by giving the name to the input tag, and by accessing them from views.py). But I have problem doing the same when it comes to the response of a dropdown menu. I have a dropdown menu, from which, a user can select multiple options. Now, how do I detect the options selected by the user and pass them to views.py so that I can add them into the database from there?

Here is the code of the dropdown menu.

        Enter City (hold Ctrl to select more than one)
        <label for="inputCity" class="sr-only">Select City to be shipped to</label><br>
        <select multiple class="form-control" id="optCity" name="city" required>
            {% for city in all_cities %}
            <option>{{city.city_name}}</option>
            {% endfor %}
        </select><br>   


Source: forms

Leave a Reply