Question

I have one data object list in the view and passing it to the template to summarize the the list. Now, from that template I want to take the data object to the next page (template) to display the details of the data object.

In my view.py

schools = PublicSchools.objects.all()
return render_to_response('searchresult.html', {'schools': schools}, context_instance=RequestContext(request))

In my template searchresult.html, I am listing the summary data of schools.

In turn I want to send the single school object to the next template (dateils.html) to display the details of particular school.

Can some one please help?

Thanks,

Était-ce utile?

La solution

You can write another view to handle your requirement

Try this sample code

URL

# pass the selected school id form template to your view   
url(r'^school/(?P<school_id>\d+)/$', schoolDetails), 

views

def schoolDetails(request, school_id):
    try:
        school = PublicSchools.objects.get(pk=school_id)
    except school.DoesNotExist:
        raise Http404
    return render(request, 'detail.html', {'school': school})

Hope this helps you :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top