felix 4 years ago
parent
commit
5b5428c34d

+ 11 - 17
frog.py

@@ -3,28 +3,22 @@ from flask import request
 from flask import make_response
 from flask import redirect
 from flask import render_template
+from flask import url_for
 app=Flask(__name__)
 
 @app.route('/')
 def index():
     return render_template('index.html')
 
-@app.route('/filter')
-def test_filter():
-    return render_template('filter.html',words='<h1>hello filter!</h1>')
+@app.route('/post/')
+def posts():
+    allposts=[{'id':1,'title':'title1'},{'id':2,'title':'title2'}]
+    return render_template('posts.html',posts=allposts)
 
-@app.route('/age/<int:myage>')
-def age(myage):
-    return render_template('age.html',myage=myage)
+@app.route('/post/<int:id>')
+def post(id):
+    return render_template('post.html',id=id)
 
-@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')
+@app.route('/article/')
+def article():
+    return redirect(url_for('posts'))

+ 0 - 0
static/.gitignore


+ 3 - 0
static/myfunction.js

@@ -0,0 +1,3 @@
+function abc(){
+    console('hello abc');
+}

BIN
static/pictures/a.png


+ 1 - 0
static/style.css

@@ -0,0 +1 @@
+.classname{color:black;}

+ 0 - 15
templates/age.html

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

+ 4 - 0
templates/base.html

@@ -4,10 +4,14 @@
         <link rel="stylesheet" href="//cdnjs.loli.net/ajax/libs/mdui/0.4.3/css/mdui.min.css">
         <script src="//cdnjs.loli.net/ajax/libs/mdui/0.4.3/js/mdui.min.js"> var SS=mdui.JQ;</script>
         <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
+        <link rel='stylesheet' href="{{ url_for('static',filename='style.css') }}">
+        <script src="{{ url_for('static',filename='myfunction.js') }}"></script>
     </head>
     <body class='mdui-theme-primary-light-green'>
         <div class="mdui-toolbar mdui-color-theme">
             <a href='/' class='mdui-typo-headline mdui-text-color-white' style='font-weight:bold'>Frog</a>
+            <a href='/' class='mdui-text-color-white'>首页</a>
+            <a href="{{ url_for('posts') }}" class='mdui-text-color-white'>文章</a>
         </div>
         <div class='mdui-container'>
             {% block content %}{% endblock %}

+ 0 - 9
templates/filter.html

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

+ 0 - 39
templates/for.html

@@ -1,39 +0,0 @@
-{% 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 %}

+ 4 - 1
templates/index.html

@@ -2,4 +2,7 @@
 
 {% block title %}Frog{% endblock %}
 
-{% block content %}<h1>hello world!</h1>{% endblock %}
+{% block content %}
+<h1>hello world!</h1>
+<img src="{{ url_for('static',filename='pictures/a.png') }}">
+{% endblock %}

+ 0 - 6
templates/macros.html

@@ -1,6 +0,0 @@
-{% 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 %}

+ 11 - 0
templates/post.html

@@ -0,0 +1,11 @@
+{% extends 'base.html' %}
+
+{% block title %}文章-{{ id }}{% endblock %}
+
+{% block content %}
+
+
+<h1>文章-{{ id }}</h1>
+<hr>
+<p>这是文章-{{ id }}的内容</p>
+{% endblock %}

+ 14 - 0
templates/posts.html

@@ -0,0 +1,14 @@
+{% extends 'base.html' %}
+
+{% block title %}文章列表{% endblock %}
+
+{% block content %}
+
+
+<h1>文章列表</h1>
+<div class='mdui-list'>
+{% for post in posts %}
+<a href="{{ url_for('post',id=post['id']) }}" class="mdui-list-item mdui-ripple">{{ post['title'] }}</a>
+{% endfor %}
+</div>
+{% endblock %}

+ 0 - 14
templates/tags.html

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