欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

一个demo

程序员文章站 2022-04-24 10:51:35
...
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body charset="UTF-8">
<form action="/login" method="post">
    username:<input type="text" name="username">
    password:<input type="password" name="password">
    <input type="submit" value="login">
</form>
{{get_flashed_messages()[0]}}
</body>
</html>

html模板

# -*- coding: utf-8 -*-
from flask import Flask, request ,flash
from flask import render_template

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
app = Flask(__name__)
app.secret_key="123"
@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        form=request.form
        username=form.get('username')
        password=form.get('password')
        if not username:
            flash('用户名为空')
            return render_template('login.html')
        if not password:
            flash('密码为空')
            return render_template('login.html')
    else:
        return render_template('login.html')

flask的路由逻辑 加入了flask闪现