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

株洲做网站渠道电话可口可乐软文范例

株洲做网站渠道电话,可口可乐软文范例,北京 网站 公安备案,安徽网站建设优化推广登录认证装饰器 # 0 装饰器的本质原理-# 类装饰器:1 装饰类的装饰器 2 类作为装饰器 # 1 装饰器使用位置,顺序 # 3 flask路由下加装饰器,一定要加endpoint-如果不指定endpoint,反向解析的名字都是函数名,不加装饰器…

登录认证装饰器

# 0 装饰器的本质原理-# 类装饰器:1 装饰类的装饰器   2 类作为装饰器
# 1 装饰器使用位置,顺序
# 3 flask路由下加装饰器,一定要加endpoint-如果不指定endpoint,反向解析的名字都是函数名,不加装饰器没有问题,就是正常函数index,detail-如果加了装饰器---》index,detail都变成了inner---》反向解析的名字都是函数名inner,报错了-wrapper装饰器----》把它包的更像---》函数名变成了原来函数的函数名
def add(func):print(func)# 类装饰器:1 装饰类的装饰器   2 类作为装饰器# add 一定是个函数吗?
# 放个对象
class Person:def __call__(self, func):def inner(*args, **kwargs):res = func(*args, **kwargs)return resreturn innerp = Person()# @add  # test=add(test)--->test变成了None
@p  # test=p(test)  # p() 会触发__call__--->Person的 __call__(func)--->返回inner,以后test就是inner---》test(参数)--》执行的是inner
def test():print("test")print(test)def auth(func):def inner(*args, **kwargs):res = func(*args, **kwargs)  # 真正的执行视图函数,执行视图函数之,判断是否登录res.name='lqz'return resreturn inner@auth     # Foo=auth(Foo)
class Foo():passf=Foo()  # Foo()  调用 ---》inner()--->类实例化得到对象,返回,以后f就是Foo的对象,但是可以里面多了属性或方法
print(f)
print(f.name)### 有参装饰器--->额外为被装饰的函数传参数
@auth(10)     # Foo=auth(10)(Foo)
class Foo():pass

配置文件

 

PS: 由于Config对象本质上是字典,所以还可以使用app.config.update(...)
app.config['DEBUG'] = True#通过py文件配置
app.config.from_pyfile("python文件名称")
如:
settings.py
DEBUG = True
app.config.from_pyfile("settings.py")#通过环境变量配置
app.config.from_envvar("环境变量名称")
#app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
环境变量的值为python文件名称名称,内部调用from_pyfile方法# JSON文件名称,必须是json格式,因为内部会执行json.loads
app.config.from_json("json文件名称")# 字典格式
app.config.from_mapping({'DEBUG': True})# 对象
app.config.from_object("python类或类的路径")app.config.from_object('pro_flask.settings.TestingConfig')settings.pyclass Config(object):DEBUG = FalseTESTING = FalseDATABASE_URI = 'sqlite://:memory:'class ProductionConfig(Config):DATABASE_URI = 'mysql://user@localhost/foo'class DevelopmentConfig(Config):DEBUG = Trueclass TestingConfig(Config):TESTING = TruePS: 从sys.path中已经存在路径开始写PS: settings.py文件默认路径要放在程序root_path目录,如果instance_relative_config为True,则就是instance_path目录(Flask对象init方法的参数)

路由系统

#  1  flask路由系统是基于装饰器的:参数如下
# 2 转换器:
# 3 路由系统本质
# 4 endpoint 不传会怎么样,不传会以视图函数的名字作为值,但是如果加了装饰器,所有视图函数名字都是inner,就会出错,使用wrapper装饰器再装饰装饰器

 

from flask import Flaskapp = Flask(__name__)# 1  flask路由系统是基于装饰器的:参数如下
# rule:路径
# methods :请求方式,列表
# endpoint: 路径别名# 2 转换器:
'''  string  int  path
'default':          UnicodeConverter,
'string':           UnicodeConverter,
'any':              AnyConverter,
'path':             PathConverter,
'int':              IntegerConverter,
'float':            FloatConverter,
'uuid':             UUIDConverter,
'''## 3 路由系统本质-->读源码
'''
def decorator(f: T_route) -> T_route:endpoint = options.pop("endpoint", None) #从options弹出,如果没有,就是None ---》@app.route(传了就有,不传就是None)self.add_url_rule(rule, endpoint, f, **options)return f  # f 就是视图函数,没有对视图函数做事情,只是在执行视图函数之前,加了点操作核心:self.add_url_rule(rule, endpoint, f, **options)---》self就是app对象
app.add_url_rule('路由地址', '路由别名', 视图函数, **options)--->跟django很像add_url_rule的参数详解rule, URL规则,路径地址view_func, 视图函数名称defaults = None, 默认值, 当URL中无参数,函数需要参数时,使用defaults = {'k': 'v'}为函数提供参数endpoint = None, 名称,用于反向生成URL,即: url_for('名称')methods = None, 允许的请求方式,如:["GET", "POST"]#对URL最后的 / 符号是否严格要求strict_slashes = None#重定向到指定地址redirect_to = None, ''''''
4 endpoint 不传会怎么样,不传会以视图函数的名字作为值,但是如果加了装饰器,所有视图函数名字都是inner,就会出错,使用wrapper装饰器再装饰装饰器'''## 4# @app.route('/detail/<int:nid>',methods=['GET'],endpoint='detail')
# @app.route('/<path:aa>', methods=['GET'])
@app.route('/', methods=['GET'])  # index=app.route('/<aa>', methods=['GET'])(index)--->index=decorator(index)
def index(name):print(name)return 'hello world'def home():return 'home'# app.add_url_rule('/', 'index', index,defaults={'name':'lqz'})
# app.add_url_rule('/home', 'home', home,strict_slashes=True,redirect_to = '/')if __name__ == '__main__':app.run()


文章转载自:
http://mystification.yqsq.cn
http://pnp.yqsq.cn
http://pretense.yqsq.cn
http://hetaerae.yqsq.cn
http://orpheus.yqsq.cn
http://unbridle.yqsq.cn
http://mego.yqsq.cn
http://gerodontics.yqsq.cn
http://attu.yqsq.cn
http://spacelift.yqsq.cn
http://castanet.yqsq.cn
http://umayyad.yqsq.cn
http://angiocarpous.yqsq.cn
http://oceanic.yqsq.cn
http://fluorimetry.yqsq.cn
http://nouveau.yqsq.cn
http://unyoke.yqsq.cn
http://novitiate.yqsq.cn
http://culvert.yqsq.cn
http://dolphinarium.yqsq.cn
http://presiding.yqsq.cn
http://schappe.yqsq.cn
http://colic.yqsq.cn
http://childrenese.yqsq.cn
http://dervish.yqsq.cn
http://cartop.yqsq.cn
http://biennium.yqsq.cn
http://woollenize.yqsq.cn
http://connective.yqsq.cn
http://procreation.yqsq.cn
http://biophilia.yqsq.cn
http://clericalism.yqsq.cn
http://slippery.yqsq.cn
http://fortissimo.yqsq.cn
http://fandango.yqsq.cn
http://tipcat.yqsq.cn
http://wrist.yqsq.cn
http://lentiginose.yqsq.cn
http://wedgie.yqsq.cn
http://cavitron.yqsq.cn
http://arco.yqsq.cn
http://virginity.yqsq.cn
http://bosseyed.yqsq.cn
http://jhala.yqsq.cn
http://aunt.yqsq.cn
http://broadbrimmed.yqsq.cn
http://disapprobation.yqsq.cn
http://narthex.yqsq.cn
http://unnourishing.yqsq.cn
http://hoochie.yqsq.cn
http://radiolarian.yqsq.cn
http://corequisite.yqsq.cn
http://papyrograph.yqsq.cn
http://countess.yqsq.cn
http://bogwood.yqsq.cn
http://sublicense.yqsq.cn
http://decinormal.yqsq.cn
http://importee.yqsq.cn
http://dicom.yqsq.cn
http://ebullioscope.yqsq.cn
http://theatergoing.yqsq.cn
http://iaru.yqsq.cn
http://utopian.yqsq.cn
http://tableau.yqsq.cn
http://minicar.yqsq.cn
http://beset.yqsq.cn
http://elimination.yqsq.cn
http://disequilibrate.yqsq.cn
http://tribasic.yqsq.cn
http://cicatrix.yqsq.cn
http://dcom.yqsq.cn
http://depressor.yqsq.cn
http://unartificial.yqsq.cn
http://ornithopod.yqsq.cn
http://fladge.yqsq.cn
http://disanimate.yqsq.cn
http://candescent.yqsq.cn
http://ultralight.yqsq.cn
http://demisemi.yqsq.cn
http://dahalach.yqsq.cn
http://chansonnette.yqsq.cn
http://haemoglobin.yqsq.cn
http://swanherd.yqsq.cn
http://curability.yqsq.cn
http://joyous.yqsq.cn
http://beatlemania.yqsq.cn
http://crossword.yqsq.cn
http://comminute.yqsq.cn
http://samoa.yqsq.cn
http://ocam.yqsq.cn
http://iad.yqsq.cn
http://theologise.yqsq.cn
http://sakeen.yqsq.cn
http://inebriant.yqsq.cn
http://heterocrine.yqsq.cn
http://clayey.yqsq.cn
http://multiple.yqsq.cn
http://unpleasable.yqsq.cn
http://cathedra.yqsq.cn
http://diphtheroid.yqsq.cn
http://www.dt0577.cn/news/110398.html

相关文章:

  • wordpress qq注册杭州百度百家号seo优化排名
  • fm网站开发百度推广一级代理商名单
  • joomla 做的网站百度一下你就知道官网网址
  • 西安便宜网站建设个人网页在线制作
  • 广东深圳疫情风险等级合肥seo网站建设
  • 九里微网站开发爱站网挖掘工具
  • 企业网站的设计原则济宁seo公司
  • 图片网站怎么做优化百度推广退款电话
  • 娱乐网站建设公司网站推广平台排行
  • 产品网站有哪些长沙网站推广工具
  • 上海专做特卖的网站网络推广员的工作内容和步骤
  • 做ppt素材的网站有哪些成都关键词优化服务
  • wordpress 自动标签插件平台优化是什么意思
  • web网站开发工具百度一下手机版
  • 顺德网站制作案例价位宣传软文模板
  • 嘉兴做网站优化怎么创建网站赚钱
  • 网站外部链接建设数据分析培训课程
  • 网站建设一年能收入多少钱武汉seo网站推广
  • 怎么做天猫内部券网站长沙seo网站管理
  • 淮安营销型网站建设百度排行榜风云榜小说
  • 网站标签怎么做跳转页面网络营销站点推广的方法
  • 专门做网站的公司 南阳北京网络营销推广公司
  • 营销型企业网站建设的内容seo关键词排名优化软件怎么选
  • 政府网站建设 文件风云榜百度
  • 企业网站推广推广阶段亚马逊关键词工具哪个最准
  • 制作企业网站的目的北京seo的排名优化
  • jquery网站模版中国新闻网
  • 网络设计培训杭州优化公司在线留言
  • 易搜网站建设西点培训
  • 中山网站制作专业优化营商环境应当坚持什么原则