我对这整个编程事情很陌生。目前,我正在开发一个烧瓶、python、SQLite 项目。我设置了一个编辑表单来编辑用户发布的列表。效果很好。然后,我复制了该代码为其创建了一个用户信息编辑表单,现在我得到了 TypeError: object of type 'NoneType' has no len() 与基本完全相同的代码。
HTML 代码。这段代码在一个 modal 里面,如果这意味着什么的话。
<form action="/edituserinfo" method="post">
<label for="name" style="float:left">Name:</label><br />
<input class="form-control" name="name" style="width:100%" placeholder="{{ user[0]['username'] }}">
<label for="email" style="float:left">Email:</label><br />
<input class="form-control" name="email" style="width:100%" placeholder="{{ user[0]['email'] }}">
<label for="city" style="float:left">City:</label><br />
<input class="form-control" name="city" style="width:100%" placeholder="{{ user[0]['city'] }}">
<button type="submit" class="btn btn-lg btn-success btn-block">SAVE!</button>
</form>
这是我的python代码。
@app.route("/edituserinfo", methods=["GET", "POST"])
@login_required
def edituserinfo():
if request.method == "POST":
user = session["user_id"]
column = ["username", "email", "city"]
for title in column:
if len(request.form.get(title)) != 0:
value = request.form.get(title)
db.execute("UPDATE users SET %s = :edit WHERE id = :id" %(title), {"edit":value, "id":user})
db.commit()
return redirect("/account")
else:
return redirect("/account")
任何帮助,建议将不胜感激!谢谢!