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=="shuyang" 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)

Flask系列(四)Flask实现简单页面登陆的更多相关文章

  1. Flask系列(二)Flask基础

    知识点回顾 1.flask依赖wsgi,实现wsgi的模块:wsgiref(django),werkzeug(flask),uwsgi(上线) 2.实例化Flask对象,里面是有参数的 app = F ...

  2. Flask系列(六)Flask实例化补充及信号

    一.实例化补充 instance_path和instance_relative_config是配合来用的. 这两个参数是用来找配置文件的,当用app.config.from_pyfile('setti ...

  3. flask系列四之SQLAlchemy(二)表关系

    一.SQLAlchemy外键约束 1.创建外键约束表结构 目标:建立两个表“用户表(user)”和“问题表( question)”,其中问题表中的作者id是是用户表的id即外键的关系.(一个用户可以有 ...

  4. flask系列四之SQLAlchemy

    一.SQLAlchemy简介 (1)flask_sqlalchemy是一套ORM框架. (2)ORM(Object Relationship Mapping):模型关系映射 (3)ORM的好处:可以让 ...

  5. 【Flask系列】开发一个简单的Flask程序

    知识点 初始化:每一个flask程序都必须创建一个程序实例,遵循WSGI(Web Server Gateway interface)协议,把请求->flask Obj; 创建实例: app = ...

  6. Flask系列06--(中间件)Flask的特殊装饰器 before_request,after_request, errorhandler

    一.使用 Flask中的特殊装饰器(中间件)方法常用的有三个 @app.before_request # 在请求进入视图函数之前 @app.after_request # 在请求结束视图函数之后 响应 ...

  7. Flask系列(五)Flask实现分页

    一.flask分页组件 from urllib.parse import urlencode,quote,unquote class Pagination(object): ""& ...

  8. Flask【第4篇】:用Flask的扩展实现的简单的页面登录

    用flask的扩展实现的简单的页面登录 from flask import Flask,render_template,request,redirect,session app = Flask(__n ...

  9. Flask系列之源码分析(一)

    目录: 涉及知识点 Flask框架原理 简单示例 路由系统原理源码分析 请求流程简单源码分析 响应流程简单源码分析 session简单源码分析 涉及知识点 1.装饰器 闭包思想 def wapper( ...

随机推荐

  1. [转] Windows局域网通过NTP设置时间同步

    NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议. 如果局域网计算机(Windows系统)可以连接Internet,可以通过“控制面板”— ...

  2. OpenCV学习:OpenCV介绍

    OpenCV全称是:Open Source Computer Vision Library(开源计算机视觉库). 于1999年由Intel建立,如今由Willow Garage提供支持. 跨平台,可以 ...

  3. windows上SVN图标不显示

    症状1:项目左侧导航栏表不能正常显示图标 方法:windows->preferences->General->Appearance->Label Decorations    ...

  4. 安装JDK出现问题 Error opening registry key'software\Javasoft\Java Runtime Environment'

    第一次安装JDK测试是否安装成功,打开cmd输入java -version 回车的时候出现如下错误: Error opening registry key'software\Javasoft\Java ...

  5. shell脚本中判断一个字符串是否是空字符串

    需求说明: 在写脚本的时候,有的时候,需要判断一个字符串是否为空,因此,在此写出如何判断一个字符串为空的方法. 简单来说,就是字符串的比较. 测试脚本: 以下的脚本用于测试str_1和str_2是否是 ...

  6. POJ 1273 Drainage Ditches (网络最大流)

    http://poj.org/problem? id=1273 Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Sub ...

  7. windows平台的游戏运行库

    每一个都在PC上玩过游戏的人,都知道要安装一些必备的游戏运行库,游戏才能运行,这里指的PC是特指Windows操作系统平台.一般来说最常见的运行库是DirectX.Microsoft Visual C ...

  8. python远程登录服务器(paramiko模块安装和使用)

    转自:http://www.jb51.net/article/46285.htm 一:简介 由paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器 ...

  9. 子Fragment获取父Fragment

    在子Fragment操作父Fragment的思路 ((FragmentRecyclerBD)FragmentAppointmentBD.this.getParentFragment()).change ...

  10. 如何快速入门单片机C语言

    一.为什么要学单片机技术? 传统的电子产品升级改造成智能化的电子产品需要用到单片机技术.也就是说传统的电子产品如电视机.电子表.计算器.数码相机.手机.MP3.遥控器.洗衣机等产品智能化.微型化,需要 ...