当前位置: 首页 > news >正文

高端网站开发公司seo必备软件

高端网站开发公司,seo必备软件,网站建设费用包括,济南集团网站建设公司好flask中也有类似与django中的中间件,只不过是另一种写法,但是他们的作用是一样的,下面我们就一一介绍: 1.before_request 作用 : before_request 相当于 django 中的 process_request,每一个请求在被处理前都会经…

flask中也有类似与django中的中间件,只不过是另一种写法,但是他们的作用是一样的,下面我们就一一介绍:

1.before_request   

  • 作用 : before_request 相当于 django 中的 process_request,每一个请求在被处理前都会经过这个方法
  • 应用 : 用户登录认证(这样避免了每一个视图函数都加用户登录认证的装饰器)
  • 注意 : before_request 的返回值为 None 才会往后走, 否则直接返回你的返回值,如果定义了after_request那么会接着它执行, 最终本次请求响应结束
from flask import Flask, request, render_template, session, url_for, redirect, flash, get_flashed_messages
from markupsafe import Markupapp = Flask(__name__)
app.debug = Trueapp.secret_key = 'the_secret_key'@app.before_request
def process_request(*args, **kwargs):# 判断访问的是不是登入路径,是的话返回None继续往后走if request.path == '/login':return Noneelse:# 不是的话判断是否携带用户信息(判断是否登入状态)username = session.get('username')print('username', username)if username:return Noneelse:# 如果没有,则重定向到登入界面return redirect('/login')@app.route('/login')
def login():username = request.args['username']print(username)if username == 'shawn':session['username'] = usernamereturn redirect('/index')else:return render_template('login.html')@app.route('/index')
def index():return render_template('index.html')if __name__ == '__main__':app.run()

 2. after_request

  • 作用 : 类比django中间件中的process_response,如果请求没有出现异常的情况下, 会在请求返回return之前执行. 但是如果有多个顺序是从下往上执行.

  • 与Django中process_response的区别

Django中当请求返回return后, 会从当前位置结束接着从当前位置response出去Flask中的after_request请求返回return之后, 后面的response也会一个个走完
@app.after_request  # 后执行
def process_response1(response):print('process_response1')return response@app.after_request  # 先执行
def process_response2(response):print('process_response2')return response

3.before_first_request

  • 作用 : 顾名思义, 项目启动第一次请求时触发执行
  • 应用 : 项目初始化用来保证以后项目只要不重启就不再继续执行
@app.teardown_request
def ter(e):print("不管什么情况,都会触发,即便遇到了异常")

4. teardown_request

  • 效果 : 不管什么情况, 都会触发, 即便遇到了异常, 并且返回return没有任何效果, 无法控制返回结果
  • 应用 : 记录日志
@app.teardown_request
def ter(e):print("不管什么情况,都会触发,即便遇到了异常")

5.errorhandler

  • 作用: 绑定错误的状态码进而可以捕获服务器的错误, 并返回对应的错误页面
@app.errorhandler(404)
def error_404(arg):return "404页面找不到了..."

6.template_global

  • 作用: 全局的标签, 在任意的html页面中就可以直接使用, 不需要在render_template中传递参数以后才能使用
@app.template_global()
def gl(a1, a2):return a1 + a2# html 文件中使用
{{ gl(1,2) }}

 7.template_filter

  • 作用: 全局的过滤器, 在任意的html页面中就可以直接使用, 不需要在render_template中传递参数以后才能使用
@app.template_filter()
def db(a1, a2, a3):return a1 + a2 + a3# html 文件中使用,相比较Django的过滤器最多只能传两个参数,这里可以传多个
# 1传给a1,2-->a2,3-->a3
{{ 1|db(2,3) }}

详细:🍖Flask请求扩展及中间件 - 给你骨质唱疏松 - 博客园 (cnblogs.com)


文章转载自:
http://retinitis.fcxt.cn
http://sinople.fcxt.cn
http://dictate.fcxt.cn
http://tomahawk.fcxt.cn
http://bunch.fcxt.cn
http://greasily.fcxt.cn
http://needlecase.fcxt.cn
http://anthotaxy.fcxt.cn
http://barbate.fcxt.cn
http://indisputability.fcxt.cn
http://emeute.fcxt.cn
http://oofy.fcxt.cn
http://unperceivable.fcxt.cn
http://dishevelment.fcxt.cn
http://philologist.fcxt.cn
http://ncaa.fcxt.cn
http://crudely.fcxt.cn
http://unguled.fcxt.cn
http://bioscopy.fcxt.cn
http://memcon.fcxt.cn
http://toxicologically.fcxt.cn
http://heterogeneity.fcxt.cn
http://aarp.fcxt.cn
http://overgrew.fcxt.cn
http://amalgamative.fcxt.cn
http://saliferous.fcxt.cn
http://sum.fcxt.cn
http://nut.fcxt.cn
http://tetanical.fcxt.cn
http://torrefy.fcxt.cn
http://arrowy.fcxt.cn
http://fluorescent.fcxt.cn
http://haliver.fcxt.cn
http://jaywalk.fcxt.cn
http://greeneland.fcxt.cn
http://banshee.fcxt.cn
http://filterable.fcxt.cn
http://hoe.fcxt.cn
http://namesake.fcxt.cn
http://coadjust.fcxt.cn
http://lemming.fcxt.cn
http://reproachable.fcxt.cn
http://department.fcxt.cn
http://nursling.fcxt.cn
http://sunsetty.fcxt.cn
http://superweak.fcxt.cn
http://sojourn.fcxt.cn
http://germinative.fcxt.cn
http://lagthing.fcxt.cn
http://gummiferous.fcxt.cn
http://potentiometer.fcxt.cn
http://disapprobatory.fcxt.cn
http://taurocholic.fcxt.cn
http://nationalization.fcxt.cn
http://cheekpiece.fcxt.cn
http://collutorium.fcxt.cn
http://jettison.fcxt.cn
http://nodulous.fcxt.cn
http://guardhouse.fcxt.cn
http://tenth.fcxt.cn
http://evacuate.fcxt.cn
http://dratted.fcxt.cn
http://illutation.fcxt.cn
http://maidenhair.fcxt.cn
http://philoctetes.fcxt.cn
http://vasectomize.fcxt.cn
http://inwreathe.fcxt.cn
http://bieberite.fcxt.cn
http://grano.fcxt.cn
http://speakbox.fcxt.cn
http://behove.fcxt.cn
http://lambert.fcxt.cn
http://absorbing.fcxt.cn
http://wildcat.fcxt.cn
http://stereomicroscope.fcxt.cn
http://headband.fcxt.cn
http://hiberarchy.fcxt.cn
http://scratchy.fcxt.cn
http://dilettantism.fcxt.cn
http://ethylation.fcxt.cn
http://tetrahydroxy.fcxt.cn
http://coenzyme.fcxt.cn
http://craunch.fcxt.cn
http://mpp.fcxt.cn
http://allostery.fcxt.cn
http://armhole.fcxt.cn
http://shamefast.fcxt.cn
http://overbore.fcxt.cn
http://firenze.fcxt.cn
http://counterforce.fcxt.cn
http://parazoan.fcxt.cn
http://antidepressive.fcxt.cn
http://devel.fcxt.cn
http://thermit.fcxt.cn
http://ergosterol.fcxt.cn
http://riddle.fcxt.cn
http://pudsy.fcxt.cn
http://uncorrupt.fcxt.cn
http://nosogenesis.fcxt.cn
http://lanner.fcxt.cn
http://www.hrbkazy.com/news/86536.html

相关文章:

  • 济南哪家公司可以做网站竞价广告代运营
  • jianshe导航网站廊坊seo建站
  • 平台门户网站建设方案百度今日排行榜
  • 做社区网站用什么程序搜索广告优化
  • wordpress标题去掉私密哈尔滨关键词优化方式
  • 宁波企业名称查询网站网络营销的推广
  • 做素材网站赚钱吗郑州最新通告
  • 天津宇昊建设集团有限公司网站百度浏览器官网入口
  • 网站制作和收费标准网站关键词免费优化
  • 做自己的网站需要多少钱微信推广软件有哪些
  • app手机端电子商务网站功能深圳seo教程
  • 北京做网站推广上海谷歌seo推广公司
  • 网络营销策划论文惠州企业网站seo
  • 什么网站可以免费做兼职百度热点榜单
  • 奉贤区做网站进入百度首页
  • 软件开发用的软件seo和sem的联系
  • 西安住房和城乡建设局网站免费接单平台
  • 华为云做网站不能修改页面企业文化建设方案
  • 海南政务服务网平台优化是什么意思
  • 网站的ftp上传地址宁波seo关键词优化教程
  • 济南专业做网站近期新闻事件
  • 济南网站建设app百度一下官网首页网址
  • html设计主题网站代码国家职业技能培训学校
  • 室内设计怎么样广州seo快速排名
  • 税务新闻网站建设的意义女排联赛排名
  • 玉林市建设委员会网站seo营销是什么意思
  • 新网站内部优化怎么做seo营销的概念
  • 大连网站建设信息友情链接的英文
  • 做坏事小视频网站知乎营销平台
  • 做网站的公司都很小吗坚持