【发布时间】:2020-09-12 11:19:39
【问题描述】:
我正在使用 Django 构建网站。我正在尝试从index.html 传递输入并使用view.py 在about.html 中显示它。
我的输入似乎被传递,因为它位于浏览器顶部的 url 中。我试图将此值存储在一个变量中并在 html 段落中显示该变量。但是它没有显示。而不是看到与变量关联的输入,我只看到带有变量名称的文本字符串。
我的index.html:
<form action="{% url 'theaboutpage' %}">
<input type="text" name="user_input">
<input type="submit" value="click here now">
</form>
我的about.html:
<a href={% url 'thehomepage' %}>go back to the home page</a>
<p>{{'input_from_home_page'}}</p>
我的views.py:
def about(request):
Hellothere = request.GET['user_input']
return render(request, 'about.html', {'input_from_home_page':Hellothere})
【问题讨论】:
-
更多详情请参阅此讨论 - Link
标签: python html django python-3.x