felix 4 years ago
parent
commit
c769fb0fe9
4 changed files with 31 additions and 17 deletions
  1. 5 17
      frog.py
  2. 16 0
      templates/base.html
  3. 5 0
      templates/hello.html
  4. 5 0
      templates/index.html

+ 5 - 17
frog.py

@@ -2,25 +2,13 @@ from flask import Flask
 from flask import request
 from flask import make_response
 from flask import redirect
+from flask import render_template
 app=Flask(__name__)
 
 @app.route('/')
 def index():
-    method=request.method
-    user_agent=request.headers['User_Agent']
-    return '请求方法为%s<br>你的UA为%s' % (method,user_agent)
+    return render_template('index.html')
 
-@app.route('/404')
-def return404():
-    return '404 not found',404
-
-@app.route('/login')
-def login():
-    response=make_response('登录成功,并记住密码!')
-    response.set_cookie('username','Felix')
-    response.set_cookie('pw_hash','d45...ae17f')
-    return response
-
-@app.route('/baidu')
-def baidu():
-    return redirect('https://www.baidu.com')
+@app.route('/hello/<user>')
+def hello(user):
+    return render_template('hello.html',user=user)

+ 16 - 0
templates/base.html

@@ -0,0 +1,16 @@
+<html>
+    <head>
+        <title>{% block title %}{% endblock %}</title>
+        <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>
+    </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>
+        </div>
+        <div class='mdui-container'>
+            {% block content %}{% endblock %}
+        </div>
+    </body>
+</html>

+ 5 - 0
templates/hello.html

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

+ 5 - 0
templates/index.html

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