felix 4 years ago
parent
commit
00dd296ffd
7 changed files with 102 additions and 8 deletions
  1. 19 3
      frog.py
  2. 15 0
      templates/age.html
  3. 9 0
      templates/filter.html
  4. 39 0
      templates/for.html
  5. 0 5
      templates/hello.html
  6. 6 0
      templates/macros.html
  7. 14 0
      templates/tags.html

+ 19 - 3
frog.py

@@ -9,6 +9,22 @@ app=Flask(__name__)
 def index():
     return render_template('index.html')
 
-@app.route('/hello/<user>')
-def hello(user):
-    return render_template('hello.html',user=user)
+@app.route('/filter')
+def test_filter():
+    return render_template('filter.html',words='<h1>hello filter!</h1>')
+
+@app.route('/age/<int:myage>')
+def age(myage):
+    return render_template('age.html',myage=myage)
+
+@app.route('/for')
+def for_return():
+    fruits=['apple','orange','watermelon']
+    profile1={'id':1,'name':'Felix','sex':'male','height':'178cm','weight':'74kg'}
+    profile2={'id':2,'name':'Lily','sex':'female','height':'169cm','weight':'50kg'}
+    profiles=[profile1,profile2]
+    return render_template('for.html',fruits=fruits,profiles=profiles)
+
+@app.route('/tags')
+def tags():
+    return render_template('tags.html')

+ 15 - 0
templates/age.html

@@ -0,0 +1,15 @@
+{% extends 'base.html' %}
+
+{% block title %}你多大了?{% endblock %}
+
+{% block content %}
+
+{% if myage<=12 %}
+<h1>你是一名少年</h1>
+{% elif myage <18 %}
+<h1>你是一名青少年</h1>
+{% else %}
+<h1>你是一名成年人</h1>
+{% endif %}
+
+{% endblock %}

+ 9 - 0
templates/filter.html

@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+
+{% block title %}filter{% endblock %}
+
+{% block content %}
+转义:         {{ words }}<br/><br/>
+不转义:       {{ words|safe }}<br/><br/>
+去除html标签: {{ words|striptags }}
+{% endblock %}

+ 39 - 0
templates/for.html

@@ -0,0 +1,39 @@
+{% extends 'base.html' %}
+
+{% block title %}遍历数据{% endblock %}
+
+{% block content %}
+
+<h2>我喜欢的水果</h2>
+<ul>
+    {% for fruit in fruits %}
+    <li>{{ fruit }}</li>
+    {% endfor %}
+</ul>
+
+
+<h2>个人信息表</h2>
+<table class='mdui-table'>
+    <thead>
+        <tr>
+            <th>id</th>
+            <th>name</th>
+            <th>sex</th>
+            <th>height</th>
+            <th>weight</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for profile in profiles %}
+        <tr>
+            <td>{{ profile['id'] }}</td>
+            <td>{{ profile['name'] }}</td>
+            <td>{{ profile['sex'] }}</td>
+            <td>{{ profile['height'] }}</td>
+            <td>{{ profile['weight'] }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+
+{% endblock %}

+ 0 - 5
templates/hello.html

@@ -1,5 +0,0 @@
-{% extends 'base.html' %}
-
-{% block title %}{{ user }}-Frog{% endblock %}
-
-{% block content %}<h1>hello {{ user }}!</h1>{% endblock %}

+ 6 - 0
templates/macros.html

@@ -0,0 +1,6 @@
+{% macro tag(words) %}
+<div class='mdui-chip'>
+    <span class='mdui-chip-title'>{{ words }}</span>
+    <span class='mdui-chip-delete'><i class='mdui-icon material-icons'>cancel</i></span>
+</div>
+{% endmacro %}

+ 14 - 0
templates/tags.html

@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+
+{% block title %}标签{% endblock %}
+
+{% block content %}
+
+{% import 'macros.html' as macros %}
+
+<h1>标签</h1>
+{{ macros.tag('好吃') }}
+{{ macros.tag('懒做') }}
+{{ macros.tag('屎尿多') }}
+
+{% endblock %}