【发布时间】:2018-10-06 22:12:05
【问题描述】:
我讨厌它无法准确说明错误是什么,但我已经探索过是否是导致此错误的数据类型。
这是我出错的函数:
def insert_recipe(recipe_id, recipe_name, img_link, recipe_link):
with sql.connect('app.db') as connection:
cursor = connection.cursor()
cursor.execute("INSERT INTO recipes (recipe_id, recipe_name, img_link, recipe_link) VALUES (?,?,?,?)", (recipe_id, recipe_name, img_link, recipe_link))
connection.commit()
这是我的功能,导致它显示在我的个人资料中:
@app.route('/profile', methods=['GET', 'POST'])
@login_required
def display_profile():
id = request.values.get('id')
title = request.values.get('title')
img_link = request.values.get('img_link')
link = request.values.get('link')
print(type(id), type(title), type(img_link), type(link))
insert_recipe(id, title, img_link, link)
insert_savedRecipes(current_user.id, id)
recipes = loadSavedRecipes()
return render_template('profile.html', name=current_user.username, recipes=recipes)
我的 SQL 架构:
CREATE TABLE recipes (
r_id integer PRIMARY KEY,
recipe_id text NOT NULL,
recipe_name text NOT NULL,
img_link text NOT NULL,
recipe_link text NOT NULL
);
我检查了所有列的数据类型,根据终端,它们都是字符串。此外,该函数似乎确实有效,因为它将配方插入到数据库表配方中。但是,当我单击导航栏中的配置文件选项卡时,这就是所有错误的时候。
所以当我的表格似乎正确插入时,我不确定为什么会出现此错误,如下图所示:
【问题讨论】: