![]() ![]() In my case, I would just modify the prior defined /hello route like this: ('/hello' ) def hello_world (): return 'Hello, World!' You do this by adding the login_required decorator to the appropriate routes. Lastly, we miss only one step which is applying the authentication to our route. You just need to retrieve the possible user/password combinations (I’ve hardcoded one example for demonstration purposes- please don’t do that!): user = pw = '1234xyz' users = Now you have basically all the functionality you need. ![]() Second, you need to define your decorator with the verify password function: def verify_password(username, password): if username in users: return check_password_hash(users.get(username), password) return False First, you need to import HTTPBasicAuth: from flask_httpauth import HTTPBasicAuth auth = HTTPBasicAuth() Therefore we need to secure the route - and the easiest and probably fastest way is to use a basic authentication for that. ![]() If you would deploy this server, everybody on the internet would be able to call your route (in case you do not provide any other security measures). I am using /hello as an example : from flask import Flask app = Flask(_name_) ('/hello' ) def hello_world (): return 'Hello, World!' if _name_ = '_main_': print('Starting app') app.run(host='0.0.0.0', debug=True, port=8080) I’ll explain you how this works, so that you can deploy your server quickly.įirst set up your Flask Server with your different routes. Therefore you should secure your Python Flask Routes with at least Basic Auth. But: This does also mean it is accessible to everyone. Deploying your Flask Server to any cloud helps to make them publicly accessible via the internet. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |