【发布时间】:2018-05-29 09:30:31
【问题描述】:
我有一个 js 代码,它在点击事件中向 /productionFloor/wip/ 发送一个 POST 请求 我有一个接收这些请求的视图(还将所有正确传递的参数打印到控制台)。 我正在尝试使用从 POST 请求接收到的数据来呈现模板,但 django 不会呈现视图。
这是我的看法:
def wip_view(request):
if request.method == "POST":
print(request.POST['id'])
print(request.POST['process'])
return render(request, 'wip.html', {'nbar': 'production_floor'})
这里是js:
$(".clickable-schedule-row").dblclick(function() {
id=$(this).children('td')[6].innerHTML;
process=$(this).children('td')[7].innerHTML;
$.post("/productionFloor/wip/", {'csrfmiddlewaretoken': $("[name=csrfmiddlewaretoken]").val(),
'id': id, 'process': process});
});
正如我所提到的,服务器正确获取请求并打印正确的数据,但它不会更改浏览器上的页面。
【问题讨论】:
-
您正在发出 ajax 请求,因此 $.post 将具有一个回调函数,该函数将返回您呈现的视图。您需要将该视图添加到您的 html 页面
-
在发布请求后在您的 js 代码中添加 console.log()。
标签: javascript django rendering