Skip to Main Content
Learning Flask Framework
book

Learning Flask Framework

by Matt Copperwaite, Charles Leifer
November 2015
Beginner content levelBeginner
250 pages
5h 16m
English
Packt Publishing
Content preview from Learning Flask Framework

Securing the admin website

As you may have noticed while testing the new admin website, it does not do any sort of authentication. In order to protect our admin site from anonymous users (or even certain logged-in users), we will add a new column to the User model to indicate that a user can access the admin website. Then we will use a hook provided by Flask-Admin to ensure that the requesting user has permissions.

The first step is to add a new column to our User model. Add the admin column to the User model as follows:

class User(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(64), unique=True) password_hash = db.Column(db.String(255)) name = db.Column(db.String(64)) slug = db.Column(db.String(64), unique=True) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Framework Cookbook - Second Edition

Flask Framework Cookbook - Second Edition

Shalabh Aggarwal
Flask Framework Cookbook

Flask Framework Cookbook

Shalabh Aggarwal

Publisher Resources

ISBN: 9781783983360Supplemental Content