简体   繁体   中英

Flask render_template() not working, TypeError: 'NoneType' object is not iterable

I have a flask app that I have taken and changed from another project that was working, after the changes I ran it and after trying multipul diffrent HTML files the render_template() function will not work. here is the code for my route: """

@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)

here is the error message I get, no matter what route I use or what HTML file I use with Jinja or not


    [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 -

检查你的上下文处理器@app.context_processor ,上下文处理器函数的返回值必须是当前登录用户的字典

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM