UndefinedError : 'user' is undefined UndefinedError : 'user' is undefined nginx nginx

UndefinedError : 'user' is undefined


Check out flask source for render_template:

It just calls template.render(context), but after the call to before_render_template.send(app, template=template, context=context)

From this, I think there is some before_render_template handler, that modifies context installed.

To debug this down, I may try to call something like this:

from flask import app@mod.route('/broken_pus', methods=['POST', 'GET'])def view_broken_pus():    template = app.jinja_env.get_or_select_template("view_broken_pus.html")    return template.render(dict(        user=g.user,        urls_for_active_clients=DeletedURLs.objects()[0].urls_for_active_clients,        other_urls=DeletedURLs.objects()[0].other_urls,    ))

If this will work, I will need to dig in who modifies context in before_render_template slot.


I suspect threading. If g is some sort of global reference then you may need to ensure that it is set up on threading.local or that threading locks are used to ensure that no thread can get hold of g.user before some 'other' thread messes with it.

See how do I make a 2.7 python context manager threadsafe for a way to handle 'globals' without sacrificing thread safety.