前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >flask 模板(flask 14)

flask 模板(flask 14)

作者头像
用户5760343
发布2019-08-13 14:31:04
5060
发布2019-08-13 14:31:04
举报
文章被收录于专栏:sktjsktj

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>{{ user.username }}'s Watchlist</title> </head> <body> <a href="{{ url_for('index') }}">← Return</a> <h2>{{ user.username }}</h2> {% if user.bio %} <i>{{ user.bio }}</i> {% else %} <i>This user has not provided a bio.</i> {% endif %} {# Below is the movie list (this is comment) #} <h5>{{ user.username }}'s Watchlist ({{ movies|length }}):</h5> <ul> {% for movie in movies %} <li>{{ movie.name }} - {{ movie.year }}</li> {% endfor %} </ul> </body> </html>

渲染模板

return render_tempalte('wxxx.html',user=user)

设置模板变量

{% set navigation=['a','b','c'] %}

设置全局变量

app.context_processor(lambda:dict(foo='abcde'))

设置循环数

app.context_processor(lambda:range(1,10))

注册全局函数

@app.template_global() def bar(): return 'i am bar'

{{ user.username }}

{{ url_for('index') }} {% if xx %} {% else %} {% endif %}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.08.09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 渲染模板
  • 设置模板变量
  • 设置全局变量
  • 设置循环数
  • 注册全局函数
  • {{ user.username }}
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档