I'm an amateur building a Flask/WTF/Jinja2 (using the Bootstrap) website, and I have not yet implemented a dropdown button. Unfortunately, I'm really struggling with the Bootstrap / Jinja2 elements (i can get my data to the jinja2, but can't get anything to render properly). If it helps as a reference, I'm emerging from the Corey Schafer school of Flask on Youtube.
Here is my WTF class statement:
class SegmentForm(FlaskForm): segmentID = SelectField(label='Choose a Segment', coerce=int, validators=[InputRequired]) Here is my route (Flask) statement:
@decks.route('/decks/segments', methods=['GET']) @login_required def segments(): form = SegmentForm() pathname = os.path.abspath(os.path.dirname(__file__)) df = pd.read_csv(pathname + '/upload_data/segment_summary.csv', index_col=None) form.segmentID.choices = df.seg_name Where I am struggling is to get the Bootstrap / Jinja2 sorted out:
<div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" id={{form.segmentID.label}}> {{ form.segmentID.label }} </button> <div class="dropdown-menu" aria-labelledby={{form.segmentID.label}}> {% for segment in form.segmentID.choices %} <option value="{{ segment }}">{{ segment }}</option> {% endfor %} </div> </div>
optionelements but the Bootstrap 4 docs use regularanchorelements with an appropriate class.