【问题标题】:HTML form element in Jinja2 is not printing the correct string. It is only printing the value before the spaceJinja2 中的 HTML 表单元素未打印正确的字符串。它只打印空格前的值
【发布时间】:2013-03-17 01:50:51
【问题描述】:

我正在使用带有cherrypy 框架的Jinja2。我已经编写了以下模板代码。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
               "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CTRnet Search</title>
</head>
<body>
<form action="search" method="post">
        <p> Please enter your query to search in the collection</p>
        <input type="text" name="query" value={{ parameters.query }}  size="35" maxlength="60" />
        <p><input type="submit" value="Search"/> <input type="reset" value="Clear"/></p>
</form>
<h2>The query is {{ parameters.query }}</h2>
<h2>About {{ parameters.numFound }} results</h2> 
</body></html>

我希望表单打印之前进行的查询的值。我正在从 parameters.query 字段中获取上一个查询。如果我的查询是“virginia”,则表单在文本框中正确显示。

如果我的查询是“virginia quake”,则表单只显示“virginia”。它在空格字符之后不打印任何内容。

是不是与不执行此操作的表单有关,还是与我的模板系统“Jinja2”有关。变量被正确传递,我可以在表单之后打印该变量。

在下面的屏幕截图中,我的查询是“virginia quake”,但表单框只打印“virginia”。我正在学习设计网页,但我不确定这里发生了什么调试。

请告诉我你的建议!

【问题讨论】:

    标签: html forms jinja2


    【解决方案1】:

    {{ parameters.query }}周围加上引号

    value="{{ parameters.query }}"
    

    【讨论】:

    • +1 是我唯一能找到这个问题答案的地方。
    猜你喜欢
    • 1970-01-01
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 2014-01-27
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    相关资源
    最近更新 更多