python flask问题,如何调用系统命令或脚本,通过按钮触发.
比如点击重启系统按钮,系统自动重启点击执行脚本,系统执行本地shell脚本
用flask模板搞不清楚按钮触发条件,只知道加载页面触发py函数.求解
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
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 jsTake jq’s ajax as an example
$.get('/reboot-system/')
Backend method:
import os def reboot_system(request): os.popen('reboot') return True
This has nothing to do with python, right? The page is adjusted with js
You can use Python’s os module
import os os.system('reboot')
flask routing receives postjquery on click monitoringajax sends running conditions to the routingThat’s it
Then the view function calls os.system or os.popen to execute system commands.
View function call os.popen(YOUR_CMD)
This has nothing to do with flask, but something to do with some system libraries
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
Backend method:
This has nothing to do with python, right? The page is adjusted with js
You can use Python’s os module
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.
View function call os.popen(YOUR_CMD)
This has nothing to do with flask, but something to do with some system libraries