search

Home  >  Q&A  >  body text

python flask问题,如何调用系统命令或脚本

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

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

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

高洛峰高洛峰2769 days ago511

reply all(7)I'll reply

  • 天蓬老师

    天蓬老师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
        

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:09:18

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:09:18

    You can use Python’s os module

    import os
    os.system('reboot')

    reply
    0
  • PHP中文网

    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

    reply
    0
  • 黄舟

    黄舟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.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:09:18

    View function call os.popen(YOUR_CMD)

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:09:18

    This has nothing to do with flask, but something to do with some system libraries

    reply
    0
  • Cancelreply