I have intended to write an search application by Django.
I am getting a NoReverseMatch error when I redirect to results page.
I posted my codes here http://pastebin.com/AL4rG9NU
Or you can read it below
urls.py
urlpatterns = patterns('pylucene.views',
(r'^$', 'index'),
(r'^search/$', 'search'),
)
views.py
def index(request):
return render_to_response('pylucene/index.html', context_instance=RequestContext(request))
def search(request):
query = request.POST['query']
search_results = search_files(query)
return HttpResponseRedirect(reverse('pylucene.views.results', args=(search_results,)))
The Error:
NoReverseMatch at /pylucene/search/
Reverse for 'pylucene.views.results' with arguments
'([(u'Documents\\Dieu khien may tinh bang y nghi.txt', u'Dieu khien
may tinh bang y nghi.txt'), '1 total matching documents.'],)' and
keyword arguments '{}' not found.
def results(request, search_results):
return render_to_response('pylucene/results.html', {'search_results': search_results}, context_instance=RequestContext(request))
I read several similar topics but I can not solve my problem.
Please help me.
Thank you so much.
I think that you are not undestanding how the
reversefunction works and what are you trying is just not posible.For the reverse function your url must be declared on urls.py for example:
Now in your code you can do
And this is how reverse works.
The real answer
I think that you do not need 2 views, but if you really want to: you have to do this to pass all the query already performed
but i think that the best that you can do is this (using GET):