How to do it...

Flask does not include a login decorator function, but the documentation does provide an example of how to roll your own (http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/). This should not be used for production use, even if it copies the Flask functionality, as you would then be responsible for ensuring that any modifications to your code don't affect the login functionality:

  1. Import the wraps function from the Python standard library's functools module. This is necessary to retain the original function's data:
        from functools import wraps
  1. A number of Flask tools need to be imported. g is a Flask application global, a special object that is only valid for the active request and returns a different value for each ...

Get Secret Recipes of the Python Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.