我想当我点击 /circle 页面中的蓝色 div 时,将值“niloofar”发送到 /final 并且输出必须是 ** niloofar **,但它不起作用。
我如何编辑它? 我想通过隐藏输入发送值。
views.py:
from django.shortcuts import render
def circle(request):
return render(request, 'circle.html')
def final(request):
matn = request.POST.get("title", "")
return render(request, 'final.html', {'matn': matn})
圆.html:
<html>
<head>
<style>
div {
width:100px;
height:100px;
background:lightblue;
}
</style>
</head>
<body>
<a href="/final">
<div></div>
<input type="hidden" name="title" value="niloofar">
</a>
最终.html:
** {{ matn }} **
urls.py:
from django.conf.urls import include, url
from secondv.views import circle, final
urlpatterns = [
url(r'^circle/', circle),
url(r'^final/', final),
]
请您参考如下方法:
您不能通过链接POST。将其改为使用 form:
<style>
.mysubmit {
width:100px;
height:100px;
background:lightblue;
}
</style>
和
<form action="/final" method="post">{% csrf_token %}
<input type="hidden" name="title" value="niloofar">
<input type="submit" class="mysubmit" value="">
</form>
同时将您的 View 更改为:
def final(request):
matn = request.POST.get("title", "")
return render(request, 'final.html', {'matn': matn})
