Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). I'm trying to render a template with the data received from the POST request, but django won't render the view.

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:

        $(".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.

like image 494
Hein Re Avatar asked Jun 21 '26 12:06

Hein Re


1 Answers

Basically you are using the ajax call from jQuery. Django return the response in json/string format. Inside the success method you will have to make changes to reflect it in the HTML pages.

 $.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.
    });
like image 94
aman kumar Avatar answered Jun 24 '26 02:06

aman kumar