kich
kich

Reputation: 764

HTML form element in Jinja2 is not printing the correct string. It is only printing the value before the space

I am using Jinja2 with cherrypy framework. I have written the below template code.

<!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>

I want the form to print the value of the query that is made before. I am getting the previous query from the parameters.query field. If my query is 'virginia', the form is displaying it correctly in the textbox.

If my query is 'virginia quake', the form is displaying only 'virginia'. It is not printing anything after the space character.

Is it something with forms that doesn't do this or something to do with my template system 'Jinja2'. The variable is being passed correctly and I am able to print that variable after the form.

In the screenshot below, my query is 'virginia quake' but the form box is printing only 'virginia'. I am learning to design webpages but I am not sure what is going on here to debug.

enter image description here

Please let me know your suggestions!

Upvotes: 3

Views: 2231

Answers (1)

jan zegan
jan zegan

Reputation: 1657

Put quotes around {{ parameters.query }}

value="{{ parameters.query }}"

Upvotes: 5

Related Questions