简体   繁体   English

POST请求后django不呈现

[英]django does not render after POST request

I have a js code, which on the on click event sends a POST request to /productionFloor/wip/ I have a view that receives those requests (also printing to the console all the arguments that were passed correctly). 我有一个js代码,在on click事件上发送一个POST请求到/ productionFloor / wip /我有一个接收这些请求的视图(还向控制台打印所有正确传递的参数)。 I'm trying to render a template with the data received from the POST request, but django won't render the view. 我正在尝试使用从POST请求接收的数据呈现模板,但django不会呈现视图。

Here is my view: 这是我的观点:

def wip_view(request):
if request.method == "POST":
    print(request.POST['id'])
    print(request.POST['process'])
return render(request, 'wip.html', {'nbar': 'production_floor'})

Here is the js: 这是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});
    });

as I mentioned, the server gets the request correctly and prints the right data, but it won't change the page on the browser. 正如我所提到的,服务器正确获取请求并打印正确的数据,但它不会更改浏览器上的页面。

Basically you are using the ajax call from jQuery. 基本上你正在使用jQuery的ajax调用。 Django return the response in json/string format. Django以json / string格式返回响应。 Inside the success method you will have to make changes to reflect it in the HTML pages. 在成功方法中,您必须进行更改以在HTML页面中反映它。

 $.ajax({
      type: "GET",
      url: '/productionFloor/wip/',
      data:"{'csrfmiddlewaretoken': $("[name=csrfmiddlewaretoken]").val(),
                        'id': id, 'process': process}",
      success: function(response) {
         // inside this function you have to bind html content using javascript, because ajax call will not render complete page.
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM