Tuesday, July 30, 2013

Fwd:



---------- Forwarded message ----------
From: Robin Lery <robinlery@gmail.com>
Date: Tue, Jul 30, 2013 at 9:22 PM
Subject:
To: django-users@googlegroups.com


Hello,
I am stuck at a point where i should be able to type in a search query on the page and it django should get back a list of matching pages if any. But it doesnt show me any pages, even though its there, and gives me an erros:

Page not found (404)

No FlatPage matches the given query.


Please point me as to where am doing wrong. Thank you.

my 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']
resuts = FlatPage.objects.filter(content__icontains=query)
template = loader.get_template('search/search.html')
context = Context({
'query':query,
'resuts':resuts
})
response = template.render(context)
return HttpResponse(response)

urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    (r'^tinymce/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': 'C:/Users/Kakar/web/cms/static/js/tinymce/' }),
    (r'', include('django.contrib.flatpages.urls')),
    (r'^search/$', 'search.views.search'),
)

settings.py:
In the installed-apps, I have installed 'search'.

default.html:

<html>
<head>
<title>{{ flatpage.title }}</title>
</head>
<body>
<form method="get" action="/search/">
{% csrf_token %}
<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>

search.html:

<html>
<head>
<title>Search</title>
</head>
<body>
<p>You searched for "{{query}}"; the results are listed below.</p>
{% if results %}
<ul>
{% for page in results %}
<li>
<a href="{{page.get_absolute_url}}">{{page.title}}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No results.</p>
{% endif %}
</body>
</html>


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment