I wrote a small flask server.
However, one of the routes was getting large so i thought of creating an external .py file, that contains all the logic in a function, and when the route gets executed, it simply calls that function in that different python file.
However, i also had to get parameters from a form.
So my new route was:
@app.route('/convert', methods=['POST'])
conversion_item = request.form.get('item')
conversion_method = request.form.get('method')
#HERE CALL THE FUNCTION
convertMy(conversion_item, conversion_method)
return redirect(url_for('index'))
However, when i execute this, i get:
File "server.py", line 24
conversion_item = request.form.get('item')
^
SyntaxError: invalid syntax
Do i have to put everything in that route inside a function?
Then i will have a function under that route, that will call another function? That seems weird to me.
How can i "glue" this?
question from:
https://stackoverflow.com/questions/66046845/flask-proper-way-of-using-routes-and-functions 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…