I have a model in which one of the fields is a role, I want the model to accept one role out of two roles something like a manager or staff. In Django for this, we have CHOICES, how we can implement it in Flask?
Asked
Active
Viewed 654 times
0
-
I think, this thread might help you: [https://stackoverflow.com/questions/31662681/flask-handle-form-with-radio-buttons](https://stackoverflow.com/questions/31662681/flask-handle-form-with-radio-buttons) – Anuj Panchal Jun 25 '21 at 05:58
1 Answers
0
Flask does support creating input fields from python using WtfForms, but that is a very long and timestaking process. The easier method is the following, You can use bootstrap SelectList to get the functionality similar to that of ChoiceFields by adding the following code to your html,
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
The result of the above mentioned code gives us something like this,
For more details, you can visit https://www.w3schools.com/Bootstrap/bootstrap_forms_inputs.asp

Harris Minhas
- 702
- 3
- 17
-
I want it in terms of rest framework, I am creating a REST API, thats the reason I asked like in Django. – Shivam555 Jun 26 '21 at 07:16