# -*- coding: utf-8 -*-
# @Time : 2022/10/01
# @Author : chron
# @FileName: hello_world.py
# @Software: PyCharm
# @E-mail : [email protected]
from flask import Flask, request, session
# 创建flask实例
app = Flask(__name__)
# 启动session前需要给个key
app.secret_key = "123456"
# session会话 保存请求前的一些状态,便于在请求之间共享信息
@app.route("/login", methods=["POST"])
def login():
if request.form.get("user") == "admin": # 请求的form表单中取参数
session["user"] = request.form.get("user")
return "admin 登录成功"
@app.route("/logout", methods=["POST"])
def logout():
user = session.get("user")
session.pop("user", None)
return f"{user} 注销成功"
# 启动web服务器 默认运行在5000端口上
# host="0.0.0.0"启用远程调用 port="8888"改变远程端口 debug=True 打开调试模式
if __name__ == '__main__':
app.run(debug=True, host="0.0.0.0", port="8888")
标签:__,flask,0.0,app,会话,session,user
From: https://www.cnblogs.com/chron/p/16746669.html