简体   繁体   中英

Render Template Exactly with Django

I'm a complete newb to Django working on a sample app. It appears that I am missing something with how templates work in Django.

I have a template file as follows:

<!DOCTYPE HTML>
<html>
<head>
<title>Zabba Dabba Doo</title>
</head>
<body>
<h1>Zabba Dabba Doo</h1>

<form action="/comparison/search/" method="get">
Search: <input type="text" name="search_terms" />
<input type="submit" value="Search" />
</form>

</body>
</html>

The views.py method is here:

def home(request):
   t = loader.get_template('comparison/index.html')
   return HttpResponse(t)

I am expecting the views method to render the html from my template, but when I test it, this is the resulting output:

<Text Node: '<!DOCTYPE HTML>
<html>
<h'>

Can anyone explain to me how to make it so my template is displayed exactly? Any help is appreciated.

You forgot to render it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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