In Django, How do I get escaped html in HttpResponse?

后端 未结 3 1196
挽巷
挽巷 2021-01-11 15:55

The following code in one of my views returns unescaped html string which cannot be parsed in frontend since it is an Ajax request.

return render_to_response         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-11 16:37

    It should escape by default.

    But, if you want to, you can explicitly force escaping.

    from django.utils.safestring import mark_for_escaping
    return HttpResponse(mark_for_escaping(loader.render_to_string(""""Render Response Syntax"""))
    

提交回复
热议问题