简体   繁体   中英

Django views.py is not rendering html file?

i am sending an object to backend (django) via ajax "POST" method. in the views.py the code runs but the render statement is not executing.

ajax

$.ajax({


                url: '{% url "chout" %}',
                data: {
                   'object': object1,
                   'csrfmiddlewaretoken':csrf
                  },
                  method: "POST",
                  dataType: 'json',
                  success: function (data) {
                             alert("success");

                     }
                   });

views.py

return render(request, "mart/checkout.html", {"total": total_price, "final_bill": final_dict})

Everything above return statement runs smoothly but somehow the return line dont run. it is not showing any error or warning either and alert is not popping either.

If the alert is popping up on screen then the return line is running. Use

alert(data);

To see if the html is in there. The window is not going to apply the HTML all on its own.

在 django 中使用 Ajax,必须返回 json 响应而不是 html 文件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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