felix 3 years ago
parent
commit
6b97582ff1
2 changed files with 20 additions and 3 deletions
  1. 11 2
      frog.py
  2. 9 1
      templates/index.html

+ 11 - 2
frog.py

@@ -1,5 +1,6 @@
-from flask import Flask,request,make_response,redirect,render_template,url_for,abort
+from flask import Flask,request,make_response,redirect,render_template,url_for,abort,flash
 app=Flask(__name__)
+app.config['SECRET_KEY']='132456'
 
 @app.errorhandler(404)
 def page_not_found(e):
@@ -32,4 +33,12 @@ from flask import abort
 def ilove(obj):
     if obj=='shit':
         abort(404)
-    return '<h1>I love %s</h1>' % obj
+    return '<h1>I love %s</h1>' % obj
+
+@app.route('/<int:num1>/plus/<int:num2>/eq/<int:num3>')
+def count(num1,num2,num3):
+    if num1+num2==num3:
+        flash('计算正确')
+    else:
+        flash('计算错误')
+    return redirect(url_for('index'))

+ 9 - 1
templates/index.html

@@ -3,6 +3,14 @@
 {% block title %}Frog{% endblock %}
 
 {% block content %}
+
+    {% with messages=get_flashed_messages() %}
+            {% if messages %}
+                {% for message in messages %}
+                <div style='color:green;background-color:lightgreen;padding:10px;'>{{ message }}</div>
+                {% endfor %}
+        {% endif %}
+    {% endwith %}
+    
 <h1>hello world!</h1>
-<img src="{{ url_for('static',filename='pictures/a.png') }}">
 {% endblock %}