I am running through a tutorial where I am supposed to create a simple search form
This is the views.py:
from django.http import HttpResponse
from django.template import loader, Context
from django.contrib.flatpages.models import FlatPage
def search(request):
    query = request.GET['q']
    results = FlatPage.objects.filter(content__icontains=query)
    template = loader.get_template
    context = Context({ 'query': query, 'results':results })
    response = template.render(context)
    return HttpResponse(response)
and this is the error I get:
Exception Value:   
'function' object has no attribute 'render'
this is the URLpattern:
(r'^search/$', 'Mysite.search.views.search'),
this is the default template:
<html>
 <head>
  <title>{{ flatpage.title }}</title>
 </head>
 <body>
 <form method="get" action="/search/">
  <p><label for="id_q">Search:</label>
  <input type="text" name="q" id="id_q" />
  <input type="submit" value="Submit" /></p>开发者_运维知识库;
 </form>
  <h1>{{ flatpage.title }}</h1>
  {{ flatpage.content }}
 </body>
</html>
And this would be the search result template:
<html>
 <head>
  <title> Search </title>
 </head>
 <body>
  <p> You searched for "{{ query }}"; the results are listed below.</p>
  <ul>
   {% for page in results %}
    <li><a href="{{ page.get_absolute_url }}">{{ page.title }}</a></li>
   {% endfor %}
  </ul>
 </body>
</html>
I simply dont get where I possibly can have gone wrong
template = loader.get_template
You should not simply assign a new variable to the function. You should actually evaluate the function.
template = loader.get_template()
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论