How to do it...

To create a simple admin interface, perform the following steps:

  1. Start with the models by adding a new BooleanField field called admin to the User model in auth/models.py. This field will help in identifying whether the user is an admin or not:
from wtforms import BooleanField 
 
class User(db.Model): 
   id = db.Column(db.Integer, primary_key=True) 
    username = db.Column(db.String(60)) 
    pwdhash = db.Column(db.String()) 
    admin = db.Column(db.Boolean()) 
 
    def __init__(self, username, password, admin=False): 
        self.username = username 
        self.pwdhash = generate_password_hash(password) 
        self.admin = admin 
 
    def is_admin(self): 
        return self.admin 

The preceding method simply returns the value of the admin field. This can have a custom implementation ...

Get Flask Framework Cookbook - Second Edition 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.