gpt4 book ai didi

python - Flask WTForms 上的经度纬度

转载 作者:行者123 更新时间:2023-12-03 16:59:40 25 4
gpt4 key购买 nike

我试图让 Flask WTF 表单读取经度和纬度,但我找不到合适的表单字段。我发现了一些成功使用 FloatField 的示例,但该示例确实很旧,并且我认为 WTF 表单已经发生了变化。

这是我正在使用的 Form 类:

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 map :
@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>

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

我正在使用的版本:

flask 0.12

flask -WTF 0.14.2

Flask-谷歌地图 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.



但是我将如何传递 step 参数超出了我的范围......

最佳答案

找到了解决方案。
而不是像这样生成表单:

{{field_form|render_form()}}

做这个:
{{wtf.quick_form(field_form, novalidate=True)}}

关于python - Flask WTForms 上的经度纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44352137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com