【问题标题】:WTForms with Material Design LiteWTForms 与 Material Design Lite
【发布时间】:2016-07-02 05:06:22
【问题描述】:

我正在尝试使用 mdl 和 flask-wtf 来呈现一个简单的表单。 根据documentation,我必须将 mdl 类添加到表单中。

5. Add one or more MDL classes, separated by spaces, to the div container, text field, field label, and error message using the class attribute.

<div class="mdl-textfield mdl-js-textfield">
  <input class="mdl-textfield__input" type="text" id="user" pattern="[A-Z,a-z, ]*">
  <label class="mdl-textfield__label" for="user">User name</label>
  <span class="mdl-textfield__error">Letters and spaces only</span>
</div>

所以我在我的模板中使用它:

<form method="POST">
  {{ form.hidden_tag() }}
  <div class=mdl-textfield mdl-js-textfield mdl-textfiedl--floating-label">
    {{ form.email.label }}
    {{ form.email(class="mdl-textfield__input") }}
  </div>
</form>

这并不完全有效,因为我需要将 mdl-textfield__label 类添加到标签中。

有没有办法使用 wtforms 来做到这一点,还是我必须忽略 {{ form.email.label }} 部分而自己制作标签?

【问题讨论】:

    标签: wtforms flask-wtforms material-design-lite


    【解决方案1】:

    我建议编写自己的模板宏。这样一来,您就可以让您的表单看起来完全符合您的要求,并且您的所有表单在整个网站上看起来都一样。

    看这里:http://bear-z.com/python/render-bootstrap-3-forms-with-wtforms-and-jinja/

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 1970-01-01
      • 2016-03-29
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多