Skip to content

Instantly share code, notes, and snippets.

@akkefa
Created October 5, 2017 17:40
Show Gist options
  • Save akkefa/9463fb2a6f41abaac123a102c0d1172d to your computer and use it in GitHub Desktop.
Save akkefa/9463fb2a6f41abaac123a102c0d1172d to your computer and use it in GitHub Desktop.
from functools import wraps
from flask import session, request, redirect, url_for
def login_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get("username") is None:
return redirect(url_for("user_app.login", next=request.url))
return f(*args, **kwargs)
return decorated_function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment