【发布时间】:2016-09-27 21:10:16
【问题描述】:
我的 TextField 表单在 html 页面中显示正常,但 DecimalFields 显示不正常。 DecimalFields 根本不显示。
我的forms.py:
from flask.ext.wtf import Form
from wtforms import TextField, validators, IntegerField, DateField, BooleanField, DecimalField
class EnterPart(Form):
Description = TextField(label='label', description="description", validators=[validators.required()])
VendorCost = DecimalField(label='label',description="cost")
我的应用程序.py:
from flask import Flask, render_template, request, redirect, url_for
def index():
form = EnterPart(request.form)
return render_template('index.html', form=form)
我的 index.html:
{% extends "base.html" %} {% import 'macros.html' as macros %}
{% block content %}
{{ form.hidden_tag() }}
{{ macros.render_field(form.Description, placeholder='Description', type='dbSerial', label_visible=false) }}
{{ macros.render_field(form.VendorCost, placeholder='Category', type='dbSerial', label_visible=false) }}
{% endblock %}
我一直在按照这里的教程进行构建: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
提前致谢。
【问题讨论】:
-
macros.render_field是做什么的? -
它应该为引导标准呈现字段。但你是对的,这就是问题所在。使用教程中的代码,macros.html 没有 DecimalField 的选项,这就是它根本不被渲染的原因。
标签: python flask wtforms flask-wtforms