Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django POST数据不工作_Python_Django_Post - Fatal编程技术网

Python django POST数据不工作

Python django POST数据不工作,python,django,post,Python,Django,Post,我想在单击/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

我想在单击
/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})
circle.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>
URL.py:

from django.conf.urls import include, url
from secondv.views import circle, final

urlpatterns = [
    url(r'^circle/', circle),
    url(r'^final/', final),
]

您不能从链接发布
POST
。将其更改为使用
表单

<style>
.mysubmit {
    width:100px;
    height:100px;
    background:lightblue;
} 
</style>

您不能从链接发布
POST
。将其更改为使用
表单

<style>
.mysubmit {
    width:100px;
    height:100px;
    background:lightblue;
} 
</style>
您正在使用
,这将发出“GET”请求。 要提交
帖子
您必须使用`

<form action='/final' method='post'>
    <input type="hidden" name="title" value="niloofar">
    <input type="submit" />
</form>

您正在使用
,这将发出“获取”请求。 要提交
帖子
您必须使用`

<form action='/final' method='post'>
    <input type="hidden" name="title" value="niloofar">
    <input type="submit" />
</form>


您在哪里定义
消息
?“不起作用”意味着什么?错误?无效结果?我已编辑了我的问题。没有错误,只是值不会出现,只会开始。那么您在哪里定义
消息
?“不起作用”意味着什么?错误?无效结果?我已编辑了我的问题。没有错误,只是值不会出现,只会开始。您肯定可以从链接发布,尽管您需要ajax:
。您的答案可能是首选的、更优的解决方案,但说您不能从链接发布是完全不正确的。如果您愿意,您可以从任何HTML元素发布任何内容,但这是否是一个好主意则完全是另一回事。。。(在大多数情况下使用表单,如您所说,使用链接是愚蠢的,但您可以使用链接。)@YungGun您的示例不是从链接发布。这是使用
标记发布的。链接与任何可点击的文本不是一回事。通过此逻辑,您还可以从
标记发布。您可以使用链接进行发布,但不能使用POST。您当然可以从链接进行发布,尽管您需要ajax:
。您的答案可能是首选的、更优的解决方案,但说您不能从链接发布是完全不正确的。如果您愿意,您可以从任何HTML元素发布任何内容,但这是否是一个好主意则完全是另一回事。。。(在大多数情况下使用表单,如您所说,使用链接是愚蠢的,但您可以使用链接。)@YungGun您的示例不是从链接发布。这是使用
标记发布的。链接与任何可点击的文本不是一回事。通过此逻辑,您还可以从
标记发布。你可以使用链接,但不能使用帖子。
<form action='/final' method='post'>
    <input type="hidden" name="title" value="niloofar">
    <input type="submit" />
</form>