简体   繁体   English

为什么在我的Django模板中会发生这种情况?

[英]Why does this happen in my template for Django?

simple%20minds is displayed when do this: 执行此操作时,将显示simple%20minds:

{{ rec.artist_name }} {{rec.artist_name}}

How do I remove the %20...and make it spaces? 如何删除%20 ...并使其成为空格?

When I put | 当我放| safe as a fitler, the error is: 作为安装工安全,错误是:

Could not parse the remainder: ' | 无法解析其余部分: safe' from 'active.artist_name | 安全”来自“ active.artist_name” | safe' 安全'

Thanks. 谢谢。

I think you're being hit by Django's relatively-new autoescaping. 我认为您正在受到Django相对较新的自动转义的打击。 What happens if you do 如果您这样做会怎样?

{{ rec.artist_name | safe }}

to avid the value being autoescaped? 证明正在自动转义的价值?

Try removing the space between the rec.artist_name and the |. 尝试删除rec.artist_name和|之间的空格。 So you should have this: 所以你应该有这个:

{{ rec.artist_name|safe }}

That'll fix the autoescaping, but I think the other commentors are correct in saying that you're storing the %20 into the db. 这样可以解决自动转义的问题,但是我认为其他评论者的正确性是您将%20存储到数据库中。 So you'll probably have to fix it on that end of things. 因此,您可能必须对此进行修复。

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

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