mtgred
mtgred

Reputation: 1449

Forwarding a Django template dictionary to another template?

Is it possible to reuse a template dictionary in another view ?

For instance, imagine a view performs a search on the db and provide the search results in a dictionary to a template. The template displays the first 10 results and has a link to display all the results in another page.

Is it possible to forward the template dictionary containing the search results to avoid having to perform the same search again ?

Upvotes: 0

Views: 125

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Not really. You can't preserve anything across page views - except by storing it somewhere, eg in the session. You couldn't put it in the template itself, as that would then need to be sent back to the server via a POST for the next request.

In any case, there's not much need to do this. If you use the built-in Paginator class to paginate your search, Django will automatically use LIMIT and OFFSET in the query so that only the objects you're actually displaying will be queried.

Upvotes: 1

Related Questions