Django Book 翻译
菜单>:
TOC
返回
原文:
The examples in the previous section have hard-coded the fact that the view is cached, because ``cache_page`` alters the ``my_view`` function in place. This approach couples your view to the cache system, which is not ideal for several reasons. For instance, you might want to reuse the view functions on another, cacheless site, or you might want to distribute the views to people who might want to use them without being cached. The solution to these problems is to specify the per-view cache in the URLconf rather than next to the view functions themselves.
翻译:
前一节中的范例将视图硬编码为使用缓存,因为 ``cache_page`` 在适当的位置对 ``my_view`` 函数进行了转换。该方法将视图与缓存系统进行了耦合,从几个方面来说并不理想。例如,你可能想在某个无缓存的站点中重用该视图函数,或者你可能想将该视图发布给那些不想通过缓存使用它们的人。解决这些问题的方法是在 URLconf 中指定视图缓存,而不是紧挨着这些视图函数本身来指定。
备注:
译者: