July 2018
Intermediate to advanced
324 pages
8h 14m
English
Let's start by creating the User model with basic functionality. The following is a code snippet of the user model.
File—auth/models.py:
import refrom datetime import datetimefrom app.config.models import BaseModelfrom flask_login.mixins import UserMixinfrom sqlalchemy.orm import synonymfrom werkzeug.security import generate_password_hash, check_password_hashfrom app import dbfrom app import login_managerclass User(UserMixin, BaseModel, db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) _email = db.Column('email', db.String(64), unique=True) password_hash = db.Column(db.String(128)) def __init__(self, **kwargs): super(User, self).__init__(**kwargs) def __repr__(self): return '<User {0}>'.format(self.email) ...Read now
Unlock full access