|
@@ -1,14 +1,44 @@
|
|
|
-from flask import Flask
|
|
|
-from flask import request
|
|
|
-from flask import make_response
|
|
|
-from flask import redirect
|
|
|
-from flask import render_template
|
|
|
+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):
|
|
|
+ return render_template('404.html'),404
|
|
|
+
|
|
|
+@app.errorhandler(500)
|
|
|
+def internal_server_error(e):
|
|
|
+ return render_template('500.html'),500
|
|
|
|
|
|
@app.route('/')
|
|
|
def index():
|
|
|
return render_template('index.html')
|
|
|
|
|
|
-@app.route('/hello/<user>')
|
|
|
-def hello(user):
|
|
|
- return render_template('hello.html',user=user)
|
|
|
+@app.route('/post/')
|
|
|
+def posts():
|
|
|
+ allposts=[{'id':1,'title':'title1'},{'id':2,'title':'title2'}]
|
|
|
+ return render_template('posts.html',posts=allposts)
|
|
|
+
|
|
|
+@app.route('/post/<int:id>')
|
|
|
+def post(id):
|
|
|
+ return render_template('post.html',id=id)
|
|
|
+
|
|
|
+@app.route('/article/')
|
|
|
+def article():
|
|
|
+ return redirect(url_for('posts'))
|
|
|
+
|
|
|
+from flask import abort
|
|
|
+
|
|
|
+@app.route('/i-love/<obj>')
|
|
|
+def ilove(obj):
|
|
|
+ if obj=='shit':
|
|
|
+ abort(404)
|
|
|
+ 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'))
|