zoukankan      html  css  js  c++  java
  • python的一些总结4

    这篇继续水 但是在水的的基础上 让搭建能正常使用flask 搭建一个站

    上篇讲到在 模板view中 输入{{xx }} 可以打印 后台传的值。 这篇讲一下 循环控制 条件控制等

    修改后台代码:

    1 @app.route('/')
    2 def hello_world():
    3     #return 'Hello World!'
    4     #return jsonify({'key':'hello'}) #返回json
    5     #return render_template_string('<html><head></head><body>1111:{{test}}</body></html>',test="tttt") #通过拼接字符串方式
    6     return render_template('index.html', test="tttttt",alist=[1,2,3,4,5,6]) #普通返回 view 方式

    修改前台代码:

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title></title>
     6 </head>
     7 <body>
     8 
     9 {{ test }}
    10 
    11 {# 这是注释的写法 #}
    12 {# 下面是 for 的写法  #}
    13 {% for n in alist %}
    14     {% if n >3 %}
    15         {{ n }}
    16     {% endif %}
    17 {% endfor %}
    18 
    19 
    20 </body>
    21 </html>

    注: for if 等表达式 需要用{%  %}  注释 需要使用{# #}

  • 相关阅读:
    滑雪(dp好题)
    田忌赛马
    反质数(Antiprimes)
    LCA-倍增法(在线)
    二模 (2) day2
    Spring Integration
    [转载] Spring MVC
    收藏夹
    Linux profile File
    git merge 与 rebase 的区别
  • 原文地址:https://www.cnblogs.com/rufus-hua/p/4701802.html
Copyright © 2011-2022 走看看