文中展示了Flask官网的Tutorial示例中用到的模板化代码片段,以备查阅。

base.html:

{% block title %}{% endblock %}

{% if g.user %}
{% else %}
{% endif %} {{ g.user['username'] }} {{ url_for('static', filename='style.css') }}
{{ url_for('auth.logout') }}
{{ url_for('auth.register') }}
{{ url_for('auth.login') }} {% for message in get_flashed_messages() %}
{% endfor %}

*.html:

{% extends 'base.html' %}

{% block header %}
{% block title %}Log In{% endblock %}
{% endblock %} {{ request.form['body'] }} {% if g.user %}
{% endif %} {% for post in posts %}
{{ post['title'] }}
{{ post['username'] }}
{{ post['created'].strftime('%Y-%m-%d') }} {% if g.user['id'] == post['author_id'] %}
{{ url_for('blog.update', id=post['id']) }}
{% endif %} {{ post['body'] }} {% if not loop.last %}
{% endif %}
{% endfor %} {{ request.form['title'] or post['title'] }} {{ request.form['body'] or post['body'] }} {{ url_for('blog.delete', id=post['id']) }}

Flask页面模板化代码片段的更多相关文章

  1. 拥有的50个CSS代码片段(上)

    1. CSS 重置 ;;;font-size: 100%; font: inherit; vertical-align: baseline; outline: none; -webkit-box-si ...

  2. Javascript 语言精粹 代码片段合集

    Javascript 语言精粹 代码片段合集 标签:Douglas-Crockford Javascript 最佳实践 原文链接 更好的阅读体验 使用一个method 方法定义新方法 Function ...

  3. CSS的50个代码片段

    1.css全局 html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a ...

  4. iPhone较为基础的代码片段

    Iphone代码片段导航 1.给UITableViewController添加ToolBar. self.navigationController.toolbarHidden = NO; //默认是隐 ...

  5. (转)每位设计师都应该拥有的50个CSS代码片段

    原文地址:http://www.cnblogs.com/fengyuqing/archive/2013/06/15/css_50.html 面对每年如此多的 新趋势 ,保持行业的领先是个很困难问题. ...

  6. 兼容ie6,ie7,ie8,firefox,chrome浏览器的代码片段

    hack实现方式和原理 #hacker{ color:red; *color:white; /*for ie6,ie7*/ *+color:blue; /*for ie7*/ _color:gray; ...

  7. 很实用的50个CSS代码片段

    原文:50 Useful CSS Snippets Every Designer Should Have          面对每年如此多的 新趋势 ,保持行业的率先是个非常困难问题. 站点设计者和前 ...

  8. python超实用的30 个简短的代码片段(三)

    Python是目前最流行的语言之一,它在数据科学.机器学习.web开发.脚本编写.自动化方面被许多人广泛使用. 它的简单和易用性造就了它如此流行的原因. 如果你正在阅读本文,那么你或多或少已经使用过P ...

  9. sublimetext3中保存代码片段

    在日常的开发工作中,不断重复上一次敲过的代码,有时确实感到伐木累."蓝瘦"(难受)."香菇"(想哭),大概表达的也是这样的心境吧!:grinning: 所以,在 ...

随机推荐

  1. 爆打团队 四则运算 beta视频

    爆打团队 四则运算 beta视频链接 http://v.youku.com/v_show/id_XMTU1MjAzNDI0NA==.html?from=s1.8-1-1.2

  2. html5 & input & accept attribute

    html5 & input & accept attribute html input accept attribute https://www.w3schools.com/TAGS/ ...

  3. html5 & upload files

    html5 & upload files https://www.sitepoint.com/html5-ajax-file-upload/ https://www.webcodegeeks. ...

  4. Windows 10 中的存储空间

    存储空间有助于保护你的数据免受驱动器故障的影响,并随着你向电脑添加驱动器而扩展存储.你可以使用存储空间将两个或多个驱动器一起分组到一个存储池中,然后使用该池的容量来创建称为存储空间的虚拟驱动器.这些存 ...

  5. c++ int转string类型

    std::string int2string(int input){ std::ostringstream ss; //clear string //ss.str(""); //s ...

  6. 点分治&动态点分治小结

    (写篇博客证明自己还活着×2) 转载请注明原文地址:http://www.cnblogs.com/LadyLex/p/8006488.html 有的时候,我们会发现这样一类题:它长得很像一个$O(n) ...

  7. 使用 docker 创建自己的镜像

    docker run 命令 镜像(image):An image is a filesystem and parameters to use at runtime. It doesn't have s ...

  8. linux(1):VMware虚拟软件下安装centos6.8

    前言:Linux是一种自由和开放源代码的类UNIX操作系统,继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统.本人学习Linux已经有一段时间了,从一开始的小白到现在的略有所悟 ...

  9. bzoj 4664: Count

    这道题和bzoj上一道叫魔法碰撞的题很像,只不过做法更加巧妙了. 一开始的想法是$f[i][j][k][0/1/2]$表示后i个数有j段当前混乱程度为k的方案,最后一维表示边界还能放几个. 转移的时候 ...

  10. SQL Server 行列相互转换命令:PIVOT和UNPIVOT使用详解

    一.使用PIVOT和UNPIVOT命令的SQL Server版本要求 1.数据库的最低版本要求为SQL Server 2005 或更高. 2.必须将数据库的兼容级别设置为90 或更高. 3.查看我的数 ...