escape problem in django templates

前端 未结 3 1230
挽巷
挽巷 2021-02-08 15:27

Let\'s say that I have this string:

s = \'

Hello!

\'

When I pass this variable to a template, I want it to be rendered as raw

相关标签:
3条回答
  • 2021-02-08 15:37

    You pretty much covered it, those are indeed all the ways to disable autoescaping.

    Are you sure the value you are talking about is actually s = '<p>Hello!</p>'?

    My hunch is that you have additional escaping somewhere in that string...

    0 讨论(0)
  • 2021-02-08 15:37

    Look at the HTML source code, is it escaped!??? I don't think so. It should be printing letter by letter, just like this:

    <
    p
    >
    H
    E
    L
    L
    O
    <
    /
    >
    
    0 讨论(0)
  • 2021-02-08 15:52

    I think you should write as follows

    {{s|escape|safe}}
    

    it is ok for me

    0 讨论(0)
提交回复
热议问题