Python 2.7 + Flask TypeError:'unicode'对象不可调用

时间:2017-04-18 01:27:58

标签: python-2.7 unicode encoding flask python-unicode

我正在尝试连接2个unicode字符串,但是我收到错误。

代码:

@app.route('/', methods = ['GET','POST'])
def index():
    form = forms.MyForm()
    rtv = []
    text = u''
    if request.method == 'POST':
        lat = form.latitude.data
        lng = form.longitude.data
        rds = form.radio.data
        sql = text("select place, tweet_id, tweet_text from tweets where ST_DistanceSphere(geom, ST_MakePoint(" + lng + ","+ lat +")) <= "+ rds +" * 1609.344 * 0.62137;")
        result = db.engine.execute(sql)
        for row in result:
            text = text+row[2] #row[2] is a unicode string
            rtv.append([row[0],row[1],row[2]])
        print text
    return render_template('base.html', form = form, rtv = rtv, text = text)

1 个答案:

答案 0 :(得分:1)

您在声明text = u''之前定义sql = text("...")。所以例外是'unicode' object is not callable