阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

错误页面定制与视图传递多个参数

110次阅读
没有评论

共计 647 个字符,预计需要花费 2 分钟才能阅读完成。

一、错误页面定制

  • 视图函数

    @app.errorhandler(404) def page_not_found(e): return render_template('error.html',title='404NOTFOUND', info=e) @app.errorhandler(500) def page_not_found(e): return render_template('error.html',title='500ERROR', info=e)
  • 定制模板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{{title}}</title> </head> <body> <h2>{{err}}</h2> </body> </html>

二、视图传递多个参数

  • locals

    def index(): a = 1 b = 2 return render_template('boot_index.html',**locals())
  • 将字典变成关键字 参数

    def index():
        return render_template('boot_index.html',**{'a':1,'b':2})
    
  • 原始传参

    def index(): return render_template('boot_index.html',a=1,b=2)
  • 将参数写在字典中

    def index(): return render_template('boot_index.html',val={'a':1,'b':2})

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-05-26发表,共计647字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中