Python Django:单击按钮后如何调用函数?
我在myviews.py中编写了一个方法,它发送一个子进程命令 我希望能够单击Django应用程序上的按钮,它将启动我编写的方法 我该怎么做 这是我当前在my views.py中的函数Python Django:单击按钮后如何调用函数?,python,html,django,methods,views,Python,Html,Django,Methods,Views,我在myviews.py中编写了一个方法,它发送一个子进程命令 我希望能够单击Django应用程序上的按钮,它将启动我编写的方法 我该怎么做 这是我当前在my views.py中的函数 def send_command(request): output = subprocess.check_output('ls', shell=True) print(output) return render(request, 'button.html')
def send_command(request):
output = subprocess.check_output('ls', shell=True)
print(output)
return render(request, 'button.html')
我在.html文件中还有一个按钮
<center><button type='submit' class='btn btn-lg'>Button</button></center>
按钮
我对这个很陌生,但任何帮助都将不胜感激。请随时询问更多信息 如果您不发送将保存在服务器中的内容,您可以将按钮更改为url url.py
from views import send_command
urlpatterns = [
url(r'^send_command$', send_command, name='send_command'),
]
html
如果您不发送将保存在服务器中的内容,您可以将按钮更改为url url.py
from views import send_command
urlpatterns = [
url(r'^send_command$', send_command, name='send_command'),
]
html
@Taylor我相信你链接的问题与Tkinter有关,而不是Django/html mayhelp@an0o0nym太好了,我去看看!感谢you@Taylor我相信您链接的问题与Tkinter有关,而不是Django/html mayhelp@an0o0nym太好了,我去看看!谢谢谢谢你,我试试看。但是,有没有办法在不切换页面的情况下调用该方法?是的,像@an0o0nymgreat的注释一样使用ajax,我将尝试两者!我很感激!谢谢,我试试看。但是,有没有办法在不切换页面的情况下调用该方法?是的,像@an0o0nymgreat的注释一样使用ajax,我将尝试两者!我很感激!