+ 1
Does anyone know how to pass arguments from flask to other python code?
Have just finished a ml project and am trying to make a website incorporating the project.
1 Odpowiedź
+ 1
There are many ways to pass arguments/parameters through HTTP to an API implemented with Flask.
You can pass through route parameters. In other words, you encode the parameter values into the URL. More details are at:
https://pythonbasics.org/flask-tutorial-routes/
You can pass through the HTTP request body. This is used with POST, PUT, DELETE... HTTP methods.
More details are at:
https://pythonbasics.org/flask-http-methods/
I would break the challenge down to these smaller steps. This should help you focus on smaller and more specific problems and creates a stronger sense of progress.
1. Create an API that always returns 0. It doesn't use any parameters. Test that this works in a web browser.
2. Create an API using Flask that responds with the sum of 2 parameters passed to it.
Respond using JSON format. Test that this works. This will prove that you can properly interpret the parameters.
3. Move the sum calculation to a function in a separate .py file. Test that the sum API still works.
4. Adjust your separate .py file to import your machine learning packages and modules. Restart Flask and test that your API returns the sum. This will ensure there are no dependency issues with the machine learning packages.
5. Add your machine learning functions to your separate .py file without invoking them. Test that the Flask API still calculates sum.
6. Adjust the parameters and invoke the machine learning functions as you want. This could be a very big step but you could ask a new question if you get stuck here.