【问题标题】:String with white space being passed incorrectly in a Django template在 Django 模板中错误地传递带有空格的字符串
【发布时间】:2022-01-22 08:30:41
【问题描述】:

我有一个名为“Vintage White”的变量,我正试图将它传递给这样的输入元素的属性。

<input name={{ attribute_value }}>

我期望元素像这样呈现

<input name="Vintage White">

但是我得到了这个

<input name="Vintage" white>

如何将带有空格的整个字符串传递给输入元素,以便获得预期的结果?

【问题讨论】:

    标签: python html django django-templates


    【解决方案1】:

    需要使用引号,否则值会在attribute_value的第一个空格之前结束,所以:

    &lt;input name=<strong>"</strong>{{ attribute_value }}<strong>"</strong>&gt;

    【讨论】:

    • 啊,是的。这样可行!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-11-12
    • 2013-10-21
    • 2013-10-21
    • 2017-12-14
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多