frog.py 835 B

1234567891011121314151617181920212223242526272829303132333435
  1. from flask import Flask,request,make_response,redirect,render_template,url_for,abort
  2. app=Flask(__name__)
  3. @app.errorhandler(404)
  4. def page_not_found(e):
  5. return render_template('404.html'),404
  6. @app.errorhandler(500)
  7. def internal_server_error(e):
  8. return render_template('500.html'),500
  9. @app.route('/')
  10. def index():
  11. return render_template('index.html')
  12. @app.route('/post/')
  13. def posts():
  14. allposts=[{'id':1,'title':'title1'},{'id':2,'title':'title2'}]
  15. return render_template('posts.html',posts=allposts)
  16. @app.route('/post/<int:id>')
  17. def post(id):
  18. return render_template('post.html',id=id)
  19. @app.route('/article/')
  20. def article():
  21. return redirect(url_for('posts'))
  22. from flask import abort
  23. @app.route('/i-love/<obj>')
  24. def ilove(obj):
  25. if obj=='shit':
  26. abort(404)
  27. return '<h1>I love %s</h1>' % obj