python flask问题,如何调用系统命令或脚本
高洛峰
高洛峰 2017-04-18 09:07:18
0
7
521

python flask问题,如何调用系统命令或脚本,通过按钮触发.

比如点击重启系统按钮,系统自动重启
点击执行脚本,系统执行本地shell脚本

用flask模板搞不清楚按钮触发条件,只知道加载页面触发py函数.求解

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(7)
Peter_Zhu

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
    
Peter_Zhu

This has nothing to do with python, right? The page is adjusted with js

Ty80

You can use Python’s os module

import os
os.system('reboot')
洪涛

flask routing receives post
jquery on click monitoring
ajax sends running conditions to the routing
That’s it

黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template