How to configure "flask" so that you can just create a file with the necessary code in a folder on the server and call it from the browser, like in PHP?
Example: http://example.com/my_flask_file_with_python_code.py
I'll try to explain the question first. OP wants an ability to execute python scripts, when hitting a particular URL - possibly via Flask.
Two possible ways I can think of
Option 1
Option 2
Get the URL from location and based on the name, simply launch scripts and return the response.
Something like :
@app.route('/scripts/<script_name>') def run_script(): proc = subprocess.Popen(["python", script_name], stdout=subprocess.PIPE, ...) proc.wait() return proc.stdout.read()
PS I won't recommend this, but just stating here for sake of completeness.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.