【发布时间】:2018-05-30 09:49:51
【问题描述】:
我刚开始使用 Django,我想在一个 html 表单中创建一个提交表单,该表单与另一个 html 页面通信。
Page1.html : 提交表单,假设我输入“Hello world”然后点击提交,我被重定向到 page2.html
Page2.html : 感谢 Get 请求 Page2.html 显示“Hello World”,因为 page2 已从 page1 加载
在第1页我使用这种形式:
<form type="get" action="/page2" style="margin: 0">
<input id="search_box" type="text" name="search_box" placeholder="Search..." >
<button id="search_submit" type="submit" >Search</button>
在 Views.py 我有这个功能:
def page2(request):
if request.method == 'GET':
search_query = request.GET.get('search_box', None)
return render(request, 'interface/recherche.html', locals())
但是我不知道如何在page2中显示已经在page1中输入的单词,非常感谢您的回答:)
【问题讨论】:
-
type="get"什么都不做。method="get"是你想要的(它是默认值,所以这就是为什么它仍然有效..)