简体   繁体   English

Django views.py 不渲染 html 文件?

[英]Django views.py is not rendering html file?

i am sending an object to backend (django) via ajax "POST" method.我正在通过ajax“POST”方法向后端(django)发送一个对象。 in the views.py the code runs but the render statement is not executing.在 views.py 中,代码运行但渲染语句未执行。

ajax阿贾克斯

$.ajax({


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

                     }
                   });

views.py视图.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. return 语句上面的所有内容都运行顺利,但不知何故return行不运行。 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.看看html是否在那里。 The window is not going to apply the HTML all on its own.该窗口不会自行应用 HTML。

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

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

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