from flask import Flask,render_template,request,redirect,session
app = Flask(__name__,template_folder='templates')
app.secret_key = "sdsfdsgdfgdfgfh" @app.before_request
def process_request():
if request.path=="/login":
return None
if not session.get("user_info"):
return redirect("/login")
return None
@app.after_request
def process_response(response):
print(2222)
return response @app.route("/login",methods=["GET","POST"])
def login():
if request.method=="GET":
return render_template("login.html")
else:
# print(request.values) #这个里面什么都有,相当于body
username = request.form.get("username")
password = request.form.get("password")
if username=="haiyan" and password=="":
session["user_info"] = username
# session.pop("user_info") #删除session
return redirect("/index")
else:
# return render_template("login.html",**{"msg":"用户名或密码错误"})
return render_template("login.html",msg="用户名或者密码错误") @app.route("/index",methods=["GET","POST"])
def index():
# if not session.get("user_info"):
# return redirect("/login")
return render_template("index.html") if __name__ == '__main__':
app.run(debug=True)

最新文章

  1. Python-函数的返回值
  2. C# 利用 DbUp 通过多个SQL Script文件完成对数据库的更新
  3. web项目知识整理
  4. Best Practices for Performance_4.Optimizing Battery Life 获取充电状态、电池信息,"sticky"类型的广播
  5. 简单理解在Mac OS X上运行ASP.NET程序
  6. 分析Linux内核中进程的调度(时间片轮转)-《Linux内核分析》Week2作业
  7. LeetCode Basic Calculator
  8. HDU 4630 No Pain No Game 树状数组+离线查询
  9. 也谈读书和书籍选择问题(C#)
  10. Socket小结
  11. java代码如何快速添加作者描述的注释最好能有详细的图解
  12. 石子合并(NOI1995)
  13. 二进制学习 wsample01a.exe
  14. python---hash查找
  15. (20)gevent协程
  16. vue中使用hotcss--stylus
  17. 区块链与Git版本工具的比较
  18. day2-作业及答案
  19. 如何在 CentOS 7 中安装或升级最新的内核
  20. java多线程----拒绝策略

热门文章

  1. 第25月第17天 django rest framwork authentication /tmp/mysql.sock
  2. 第20月第18天 小码哥swift
  3. Java基础_0305:简单Java类
  4. Python 包
  5. mongodb 案例 ~ 经典故障案例
  6. 前端 - jsonp 跨域ajax
  7. logistic回归为什么要使用sigmoid函数
  8. ubuntu14.04配置face_recognition环境
  9. 用OZ工具制作openstack镜像
  10. oracle启用归档日志