python flask问题,如何调用系统命令或脚本,通过按钮触发.
比如点击重启系统按钮,系统自动重启
点击执行脚本,系统执行本地shell脚本
用flask模板搞不清楚按钮触发条件,只知道加载页面触发py函数.求解
天蓬老师2017-04-18 09:09:18
The questioner mentioned by the experts may not understand how to use it
For example, the url is /reboot-system/, and the front end calls the url through js
Take jq’s ajax as an example
$.get('/reboot-system/')
Backend method:
import os
def reboot_system(request):
os.popen('reboot')
return True
天蓬老师2017-04-18 09:09:18
This has nothing to do with python, right? The page is adjusted with js
PHP中文网2017-04-18 09:09:18
flask routing receives post
jquery on click monitoring
ajax sends running conditions to the routing
That’s it
黄舟2017-04-18 09:09:18
flask routing receives post
jquery on click monitoring
ajax sends running conditions to the routing
That’s it
Then the view function calls os.system or os.popen to execute system commands.
大家讲道理2017-04-18 09:09:18
This has nothing to do with flask, but something to do with some system libraries