我目前正在使用 django 制作一个网站。现在我想使用网站上的按钮从我的模板/ View 执行 python 脚本。这应该是可能的,但老实说我不知道怎么做。
最好有一个例子。
感谢您的帮助。
最佳答案
好吧,现在它开始工作了,只是想我会写下我的答案:
view.py:
import script as gh
def get_hostname(request):
gh.main()
return HttpResponseRedirect('/')
urls.py:
...
url(r'^get_hostname/$', 'thinco.views.get_hostname'),
...
模板中的某处:
...
<form action="/get_hostname/" method="GET">
<input type="submit" value="Liste der Thin Clients laden">
</form>
...
关于python - 我想在我的网站上有一个按钮来执行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7594348/