开发者

Forwarding a Django template dictionary to another template?

开发者 https://www.devze.com 2023-02-01 00:06 出处:网络
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 dis

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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消