I want to create a dropdown list in a form. I followed this approach here. If I use {{ form.as_p }}, the dropdown list renders just fine. But rendering the form using as_p looks terrible. Instead, I loop through the form fields and access their parameters so I can stylize the inputs. I try to catch the field of the dropdown list using an if-statement with condition field.widget.input_type == "select". When the page renders, I should see "This is where my dropdown goes" where my dropdown list field is supposed to be. But that doesn't happen, the field gets rendered as a text input like every other field, so my if-statement is not working. I debugged my view function and confirmed that the field corresponding to the dropdown list does have parameter .widget.input_type == "select". What am I doing wrong?
<form action="{% url 'myapp:newrecord' %}" method='post'>
{% csrf_token %}
{% for field in form %}
<div class="form-group row">
{% if field.widget.input_type == "select" %}
<p>This is where my dropdown goes.</p>
{% else %}
<label for="{{ field.id_for_label }}" class="col-sm-2 col-form-label">{{ field.label }}</label>
<div class="col-sm-10">
<input type="text" name="{{ field.html_name }}" class="form-control" id="{{ field.id_for_label }}" placeholder="{{ field.label }}" required>
</div>
{% endif %}
</div>
{% empty %}
<p>This shouldn't be empty but it is.</p>
{% endfor %}
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>