[英]How do I configure “flask” to just run files from the browser?
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?如何配置“flask”,以便您可以在服务器上的文件夹中创建一个包含必要代码的文件并从浏览器中调用它,例如 PHP?
Example: http://example.com/my_flask_file_with_python_code.py示例: 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. OP 希望能够在遇到特定 URL 时执行 python 脚本 - 可能通过 Flask。
Two possible ways I can think of我能想到的两种可能的方法
Option 1选项1
Option 2选项 2
Get the URL from location and based on the name, simply launch scripts and return the response.从位置获取 URL 并根据名称,只需启动脚本并返回响应。
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. PS我不会推荐这个,只是为了完整起见在这里说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.