Cookie
Session
# views.py: 路由 + 视图函数
import datetimefrom flask import Blueprint, render_template, request, redirect, session
from .models import *# 蓝图
blue = Blueprint('user', __name__)# 首页 可以写两个路由,都是访问同一个函数
@blue.route('/')
@blue.route('/home/')
def home():# 4. 获取cookie# username = request.cookies.get('user')# 获取sessionusername = session.get('user')print('username',username)return render_template('home.html', username=username)# 登录
@blue.route('/login/', methods=['GET', 'POST'])
def login():# GET:访问登录页面if request.method == 'GET':return render_template('login.html')# POST: 实现登录功能elif request.method == 'POST':pass# 1. 获取前端提交过来的数据username = request.form.get('username')password = request.form.get('password')# 2. 模拟登录:用户名和密码验证if username == 'lisi' and password == '123':# 登录成功response