Replacing a character in Django template

后端 未结 2 1884
慢半拍i
慢半拍i 2021-01-01 20:54

I want to change & to and in the my page\'s meta description.

This is what I tried

{% if \'&\' in dj.name %}
           


        
2条回答
  •  迷失自我
    2021-01-01 21:28

    The documentation says thus:

    Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display.

    You will have to edit dj.name beforehand.

    Edit: looks like Pythoner knows a better way: registering a custom filter. Upvote him ;)

提交回复
热议问题