Flask WTF 表单上的经度纬度

Longitude Latitude on Flask WTF Forms

我正在尝试让 Flask WTF 表单读取经度和纬度,但找不到合适的表单域。我找到了一些成功使用 FloatField 的例子,但这些例子真的很老,我认为 WTF 形式已经发生了变化。

这是我正在使用的表格class:

class GetFieldForm(Form):
    field_name = StringField(Designation')
    field_latitude = FloatField(u'Latitude', default=-30, validators=[InputRequired()], description='48.182601')
    field_longitude = FloatField(u'Longitude', default=150,
                                 validators=[InputRequired()], description='11.304939')
    submit = SubmitField(u'Signup')

将值从表单传递到 Google 地图:

@frontend.route('/demo')
def demo():
        field_form = GetFieldForm()
        if field_form.validate_on_submit():
            flash('Hello, {}. You have successfully signed up'
                  .format(escape(field_form.name.data)))

            field_latitude = field_form.field_latitude.data
            field_longitude = field_form.field_longitude.data
            mymap = Map(
                identifier="view-side",
                lat=field_latitude,
                lng=field_longitude,
                zoom=18,
                style="height:720px;width:720px;margin:0;",  # hardcoded!
                markers=[(field_latitude, field_longitude)],
                maptype='SATELLITE'
            )

            return render_template('demo.html', mymap=mymap, field_form=field_form)

使用以下 Jinja2 模板:

<div class="container-fluid">

            <div class="row-fluid">

                <div id="map" class="col-md-7">
                    {{mymap.html}}
                </div>

               <div class="col-md-5">
                   <div class="panel panel-default">
                <!-- Panel Title -->
                <div class="panel-heading">
                    <h2 class="panel-title text-center">Locate Your Field  <span class="glyphicon glyphicon-map-marker"></span></h2>

                 <div class="panel-body">
                 {% if request.args.get('legacy') -%}
                   {{wtf.quick_form(field_form, novalidate=True)}}
                 {%- else -%}
                   {{field_form|render_form()}}
                 {%- endif %}
                     </div>
               </div>
            </div>
        </div>

问题是,表单不允许我将经度和纬度作为浮点数传递:

我使用的版本:

烧瓶 0.12

Flask-WTF 0.14.2

Flask-Google地图https://github.com/rochacbruno/Flask-GoogleMaps

编辑:提示我错误可能与 FLASK-Bootstrap>

有关

The problem is Flask-Bootstrap, that you seem to be using. https://github.com/mbr/flask-bootstrap/blob/master/flask_bootstrap/forms.py#L97-L99 It overrides the float type to use "number" as input type, which is not quite right there, since "number" in html5 is limited to integers if the step argument is not provided. So you have to set the step attribute on your input field, though I don't know how to do that with Flask-Bootstrap. Preferably something like step="0.000001" should suffice.

但是我无法传递步骤参数...

找到解决办法。 而不是像这样生成表单:

{{field_form|render_form()}}

这样做:

{{wtf.quick_form(field_form, novalidate=True)}}