This article describes how to specify the View Cache in URLconf under the Django framework. Django is the most popular among the various Python web frameworks, if you need it, you can see that the view is coupled with the cache system, which is not ideal in several aspects. For example, you may want to reuse the View function on a site without caching, or you may want to publish the view to those who do not want to use it through caching. The solution to these problems is to specify the View Cache in URLconf, rather than the view function itself.
It is very easy to do this: a cache_page is simply wrapped when these View functions are used in URLconf. Here is the URLconf you have just used: this is the previous URLconf:
Urlpatterns = ('', (r' ^ foo/(\ d {1, 2})/$ ', my_view ),)
The following is the same URLconf, but the my_view is wrapped in cache_page:
From django. views. decorators. cache import cache_pageurlpatterns = ('', (r' ^ foo/(\ d {1, 2})/$ ', cache_page (my_view, 60*15 )),)
If you use this method, do not forget to import cache_page in URLconf.