我想在我的网站上有一个按钮来执行python脚本

wag*_*lix 6 python django templates view

我目前正在使用django制作一个网站.现在我想通过网站上的按钮从我的模板/视图执行python脚本.它应该是可能的,但说实话,我不知道如何.

一个例子是最好的.

谢谢你的帮助.

wag*_*lix 4

现在好了,我想我会写下我的答案:

视图.py:

import script as gh

def get_hostname(request):
        gh.main()
        return HttpResponseRedirect('/')
Run Code Online (Sandbox Code Playgroud)

网址.py:

... 
url(r'^get_hostname/$', 'thinco.views.get_hostname'), 
...
Run Code Online (Sandbox Code Playgroud)

模板中的某处:

...
     <form action="/get_hostname/" method="GET">
        <input type="submit" value="Liste der Thin Clients laden"> 
    </form>
...
Run Code Online (Sandbox Code Playgroud)