2016-09-27 2 views
-1

Мои формы TextField отображаются на html-странице, но не DecimalFields. Десятичные поля не отображаются вообще.Флажок wtforms DecimalField не отображается в HTML

Мой 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") 

Мой 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) 

Мой 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

Заранее спасибо.

+1

что делает 'macros.render_field' делать? – reptilicus

+0

Он должен отображать поле для стандартов бутстрапа. Но вы правы, вот откуда эта проблема. Используя код из учебника, macros.html не имеет опции для DecimalField, поэтому он вообще не отображается. – Generacy

ответ

0

У 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> 

к:

<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>