rest.py 505 B

1234567891011121314151617181920212223
  1. from flask import Flask
  2. from flask import jsonify
  3. from flask_httpauth import HTTPBasicAuth
  4. app = Flask(__name__)
  5. auth = HTTPBasicAuth()
  6. @app.route('/rest-auth')
  7. @auth.login_required
  8. def get_response():
  9. return jsonify('You are an authenticate person to see this message')
  10. @auth.verify_password
  11. def authenticate(username, password):
  12. if username and password:
  13. if username == 'roy' and password == 'roy':
  14. return True
  15. else:
  16. return False
  17. return False
  18. if __name__ == "__main__":
  19. app.run()