Python 未在HTML中显示文本字段
我的TextField表单在html页面中显示良好,但在DecimalFields中显示不好。十进制字段根本不显示 My forms.py:Python 未在HTML中显示文本字段,python,flask,wtforms,flask-wtforms,Python,Flask,Wtforms,Flask Wtforms,我的TextField表单在html页面中显示良好,但在DecimalFields中显示不好。十进制字段根本不显示 My forms.py: from flask.ext.wtf import Form from wtforms import TextField, validators, IntegerField, DateField, BooleanField, DecimalField class EnterPart(Form): Description = TextField(l
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")
My application.py:
from flask import Flask, render_template, request, redirect, url_for
def index():
form = EnterPart(request.form)
return render_template('index.html', form=form)
My 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 %}
我一直在这里根据教程进行构建:
提前感谢。Macros.html没有处理DecimalField的选项。通过为DecimalField添加渲染选项,它现在可以正确显示 我将macros.html中的块更改为:
<div class="form-group {% if field.errors %}has-error{% endif %} {{ kwargs.pop('class_', '') }}">
{% if (field.type != 'HiddenField' or field.type !='CSRFTokenField') and label_visible %}
<label for="{{ field.id }}" class="control-label">{{ field.label }}</label>
{% endif %}
{% if field.type == 'TextField' %}
{{ field(class_='form-control', **kwargs) }}
{% endif %}
{% if field.errors %}
{% for e in field.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
</div>
{%if(field.type!=“HiddenField”或field.type!=“CSRFTokenField”)和标签\u visible%}
{{field.label}
{%endif%}
{%if-field.type='TextField%}
{{field(class='form-control',**kwargs)}
{%endif%}
{%if field.errors%}
{%e在field.errors%}
{{e}
{%endfor%}
{%endif%}
致:
{%if(field.type!=“HiddenField”或field.type!=“CSRFTokenField”)和标签\u visible%}
{{field.label}
{%endif%}
{%if-field.type='TextField%}
{{field(class='form-control',**kwargs)}
{%endif%}
{%if-field.type='DecimalField%}
{{field(class='form-control',**kwargs)}
{%endif%}
{%if field.errors%}
{%e在field.errors%}
{{e}
{%endfor%}
{%endif%}
宏.render\u字段的作用是什么?它应该为引导标准呈现字段。但你是对的,这就是问题的根源。使用教程中的代码,macros.html没有DecimalField选项,这就是它根本没有被渲染的原因。
<div class="form-group {% if field.errors %}has-error{% endif %} {{ kwargs.pop('class_', '') }}">
{% if (field.type != 'HiddenField' or field.type !='CSRFTokenField') and label_visible %}
<label for="{{ field.id }}" class="control-label">{{ field.label }}</label>
{% endif %}
{% if field.type == 'TextField' %}
{{ field(class_='form-control', **kwargs) }}
{% endif %}
{% if field.type == 'DecimalField' %}
{{ field(class_='form-control', **kwargs) }}
{% endif %}
{% if field.errors %}
{% for e in field.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
</div>