无法检索烧瓶中的值

时间:2020-04-05 10:48:47

标签: python python-3.x flask pymongo

我使用pymongo并检索了存储在mongo地图集中的所有集合中的值,我只需要lat,所以我像这样存储了所有lat。

a_float = [a['Lat'] for a in results1] 

其中result1 = collection1.find({})和collection1 = db [“ Latitude”]

现在放在烧瓶中,我正在尝试将输入纬度与蒙戈纬度进行比较。每次执行其他条件时。我的烧瓶代码如下

@app.route("/")
def hello():
    return render_template('home.html')

@app.route("/echo", methods=['POST'])
def echo():
    a=request.form['lat']
    b=request.form['long']

    if a in a_float:
        msg = "present"
        return render_template('root.html', msg=msg, a=a, b=b)
    else:
        msg = "absent"

    return render_template('root.html', msg=msg, a=a, b=b)

我的HTML代码home.html

<!DOCTYPE html>
    <head>

    </head>
    <body>
    <form method="POST" action="/echo">

        Enter the lat<input type="text" name = 'lat' >
        Enter the long<input type="text" name = 'long' >

        <input type="submit" value="submit">

    </form>
    </body>

</html>

root.html

<!DOCTYPE html>
<head>
</head>
<form>        
    </form>
    <body>


{{ msg }}
    Lat : {{a}}
    Long : {{b}}

    </body>
</html>

1 个答案:

答案 0 :(得分:1)

您确定比较类型相同吗?

如果list元素具有浮点值,请尝试在比较之前进行转换:

a = float(request.form['long'])

a = request.form.get('long', type=float)

See more about this way here

相关问题