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

标签 python django templates view

我目前正在使用 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/

相关文章:

c++ - 成员函数的部分特化

python - 使用 Tweepy 将屏幕名称列表转换为用户 ID

python - 根据条件从Python字典中选择特定范围的元素

python - Django : Migration of polymorphic models back to a single base class

python - 查询中外键的最大出现次数

php - Smarty 日期和时间比较

templates - 如何防止Coldfusion将cfform.js注入(inject)head部分?

python - 在 nginx ubuntu 下服务多个 gunicorn django 实例

python - Excel 列中数字更改的次数

Pythonic Django 表单 Charfield CSS