Guest User

Untitled

a guest
Oct 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. # app/main.py
  2. from flask import Flask, abort, jsonify
  3. from models import db
  4. from models.post import Post
  5. import config
  6.  
  7. app = Flask(__name__)
  8. app.config['SQLALCHEMY_DATABASE_URI'] = config.alchemy_uri()
  9. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  10.  
  11. db.init_app(app)
  12.  
  13. @app.route('/', methods=['GET'])
  14. def index():
  15. return 'Hello World!'
  16.  
  17. @app.route('/post/<int:id>', methods=['GET'])
  18. def get_post(id):
  19. post = Post.query.get(id)
  20. if not post:
  21. return abort(404)
  22.  
  23. return jsonify({
  24. 'content': post.content,
  25. 'author_email': post.author_email,
  26. 'created_time': post.created_time,
  27. })
  28.  
  29. if __name__ == '__main__':
  30. app.run(host='0.0.0.0', debug=True, port=8080)
Add Comment
Please, Sign In to add comment