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

后端 未结 3 1109
挽巷
挽巷 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:29

    Lakshman Prasad's answer is technically correct, but a bit cumbersome. A better way to escape text would be (as suggested in a comment by miku above):

    from django.utils.html import escape
    return HttpResponse(escape(some_string))
    

提交回复
热议问题