python - flask - how to redirect outside of app context -
python - flask - how to redirect outside of app context -
i'm trying simple redirect function not decorated @app decorator, how can (presumably need create check_status() aware of app context)?
def check_status(): homecoming redirect("http://google.com") @dashboard_bp.route('/dashboard') @login_required def website_users(): check_status() homecoming render_template('website_users.html')
the context active globally. when phone call check_status()
website_users()
, context active.
not redirect()
callable needs context; produce response()
object, no context required.
you are ignoring homecoming value of check_status()
however. perhaps need check if check_status()
returning something:
status = check_status() if status not none: # redirect homecoming status
alternatively, create check_status()
raise exception. can handle exception in view (and turn redirect response there), or can register errorhandler()
function handle dedicated exception:
class statusdenied(exception): pass @app.errorhandler(statusdenied) def redirect_on_status_denied(error): homecoming redirect("http://google.com") def check_status(): raise statusdenied
python http flask
Comments
Post a Comment