Skip to content

Instantly share code, notes, and snippets.

@Julian-Nash
Last active August 30, 2018 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Julian-Nash/1386d91f3e8507d0ee2e1fb130acaeb0 to your computer and use it in GitHub Desktop.
Save Julian-Nash/1386d91f3e8507d0ee2e1fb130acaeb0 to your computer and use it in GitHub Desktop.
Flask session wrapper - Control view access with this decorator
def in_session(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if session.get("LOGGED_IN") == False:
return redirect(url_for('login'))
return f(*args, **kwargs)
return decorated_function
# Usage --------------------------------------------------------
@app.route("/shop/profile", methods=["GET", "POST"])
@in_session
def profile():
user = get_user()
page_title = "Profile"
return render_template("frontent/client_profile.html", app_title=app_title, page_title=page_title, user=user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment