Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask_restful import Api
- app = Flask(__name__)
- ...
- api = Api(app)
- api.add_resource(ContactList, "/contacts")
- if __name__ == '__main__':
- from object_SQLAlchemy import db
- db.init_app(app)
- app.run(port=5000)
- class Contact(Resource):
- parser = reqparse.RequestParser()
- parser.add_argument(
- 'contact_no',
- type=str,
- required=True,
- help="This field cannot be left blank"
- )
- @throttling.Throttle("10/m", strategy=2)
- def get(self, name):
- contact = Contacts.findbyname(name)
- if contact:
- return contact.json()
- return {"message": "Contact does not exist."}, 404
- from ..app_alchemy import api, app
- @api.errorhandler(Exception)
- def handle_error(e):
- return {"error": str(e)}
- @app.errorhandler(500)
- def handle_error_app(e):
- return {"error": str(e.args[0])}
- @app.handle_exception(Exception)
- def handle_it_app(e):
- return {"error": str(e.args[0])}
- @api.handle_exception(Exception)
- def handle_it(e):
- return {"error": str(e.args[0])}
- {"message": "Internal Server Error"}
Add Comment
Please, Sign In to add comment