Answer a question

In forms created by flask-wtf, how can I specify the height and width of text field input

{% extends "base.html" %}
{% block title %} Title {% endblock %}
{% block body %}
 <form method="POST">
     {{ form.textfld.label }} <br>
     {{form.textfld(size=100)}}
 </form>
{% endblock %}

This is the only example I can find which changes only the width but not height. I tried to add a class to it and target the class in base.html but nothing is changed.

Answers

if you add a render_kw dict to the form specification:

class Form(Form):
     field = SomeField(*args, render_kw=dict(class='my_class'))

then in the HTML the text class="my_class" will be automatically rendered for the field, so you customise the properties via the CSS class.

Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐