我有一个flask应用程序,该应用程序已经从另一个正在运行的项目中获取并进行了更改,在运行更改后并尝试了多脉冲不同的HTML文件后,render_template()函数将不起作用。这是我的路线的代码: “”“
@app.route("/login", methods=["GET", "POST"])
def login_route():
print("in login route")
form = LoginForm()
if "logged_in" in session:
print("found in sesstion")
return redirect(url_for("index_route"))
if form.validate_on_submit():
print("FORM VALID")
feadback = val_login(form.username, form.password)
print(feadback)
if feadback[0] == 1: # correct usr/psw
print("got through if")
agent = request.user_agent.string
time = get_time()
newHistory = LoginHistory(usr_id=int(feadback[1]), time=time, device_type=agent)
db.session.add(newHistory)
db.session.commit()
session["logged_in"] = True
print(session["logged_in"])
session["username"] = feadback[3]
session["id"] = feadback[1]
if feadback[2]:
session["admin"] = True
return redirect(url_for("index_route"))
else:
print("error")
return render_template("login.html", form=form, error="true")
print("at render")
return render_template("login.html", form=form)
这是我收到的错误消息,无论我使用哪种路由或是否使用了与Jinja一起使用的HTML文件
[2019-12-06 00:30:47,027] ERROR in app: Exception on /login [GET]
Traceback (most recent call last):
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/mnt/chromeos/removable/System/Code/Python/Flask/Hanc Notes - api for herald/app.py", line 555, in login_route
return render_template("login.html", form=form)
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/templating.py", line 136, in render_template
ctx.app.update_template_context(context)
File "/home/avineedswifi/.local/lib/python3.5/site-packages/flask/app.py", line 838, in update_template_context
context.update(func())
TypeError: 'NoneType' object is not iterable
127.0.0.1 - - [06/Dec/2019 00:30:47] "GET /login HTTP/1.1" 500 -
答案 0 :(得分:1)
检查您的上下文处理器@app.context_processor
,上下文处理器函数的返回值必须是当前登录用户的字典