编辑:结果我犯了一个愚蠢的错误,谢谢你的帮助!在
我想从sqlite表中获取值,我使用fetchnone()
来获取最后一行的值。但是我在调用那个函数时遇到了一个未知的错误
'sqlite3.Cursor' object has no attribute 'fetchnone'
这是我的重定向函数代码,我不知道错误在哪里
^{pr2}$谢谢!在
编辑:
我知道这违反了Stackoverflow的一些规则,但我想问另一个关于重定向的问题:
我试图建立一个网址缩短,但我有错误时,重定向用户到较长的网址。我用SQLite作为数据库。 这是我的重定向代码:
@app.route('/<short_url>')
def redirect(short_url):
conn = sqlite3.connect('url.db')
cursor = conn.cursor()
result_cur = cursor.execute("SELECT URL FROM WEB_URL WHERE S_URL = ?;" ,(short_url,) )
try:
redirect_url = result_cur.fetchone()[0]
print redirect_url
conn.close()
return redirect(redirect_url , code = 200)
except Exception as e:
error = e
return render_template('index.html' , error = error)
fetchone()[0]
确实返回了正确的长URL,但是在单击生成的短URL时,我得到了这个错误
'NoneType' object has no attribute '__getitem__'
不应该有NoneError
,因为我从数据库中得到了一个值。在
您有错误:fetchone()是正确的方法。在
参考号:https://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.fetchone
相关问题 更多 >
编程相关推荐