tags:

views:

27

answers:

1

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

+1  A: 
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()
S.Lott
Yes that was it! Thanks a million!
MacPython