create a login database in flask code example

Example 1: flask console log

from __future__ import print_function # In python 2.7
import sys

@app.route('/button/')
def button_clicked():
    print('Hello world!', file=sys.stderr)
    return redirect('/')

Example 2: flask authentication user without database

class User(UserMixin):

    def __init__(self, username, hash):
        self.name = username
        self.hash = hash

    @property
    def id(self):
        return self.name


@self.server.route('/api/login', methods=['GET', 'POST'])
def login():
    user = load_user(request.values.get('username'))
    if user and user.hash == request.values.get('hash'):
        login_user(user)
        return jsonify(status='ok', username=user.username)
    else:
        return jsonify(status='error', message='wrong username or hash')

Example 3: flask user create account at

<p><i class="fa fa-fw fa-calendar"></i>Create account at {{ user.create_account.strftime('%Y-%m-%d') }}</p>