<input type="text"> Django 模板中字符串中的空格

Kru*_*ull 2 django text templates spaces input

我在 Django 模板中有这个代码:

input  type="text" name="ppoisNomePOI"  value={{ request.session.ppoisNomePOI }}
Run Code Online (Sandbox Code Playgroud)

如果我的“request.session.ppoisNomePOI”是“John”,那么在页面中它会在输入中出现“John”,但是如果我的“request.session.ppoisNomePOI”是“John Flanders Simpson”,它只会出现“John”

我认为这是值中的空格有问题。

The*_*heZ 5

从它的声音来看,浏览器可能将后续单词视为空属性并被解释为:

<input type="text" name="ppoisNomePOI" value="John" Flanders Simpson>
Run Code Online (Sandbox Code Playgroud)

尝试在值周围加上引号。

value="{{ request.session.ppoisNomePOI }}"
Run Code Online (Sandbox Code Playgroud)

这将迫使它被解释为:

<input type="text" name="ppoisNomePOI" value="John Flanders Simpson">
Run Code Online (Sandbox Code Playgroud)