Thursday, September 29, 2016

Re: Cache-Control header for Flat Pages

Hi Michal,

Thanks for your response. My mistake that I should have mentioned that we are using Django 1.8. The decorator cache_control I think was introduced in 1.9. Would there be something similar in 1.8?


On Thursday, September 29, 2016 at 5:08:08 PM UTC+5:30, Michal Petrucha wrote:
On Thu, Sep 29, 2016 at 03:47:11AM -0700, Web Architect wrote:
> Hi Serge,
> Thanks for your response.
> We do not have any Views implemented for flatpages. I think they are Django
> internal stuff for static html content (something like a CMS):
> Have used the url pattern as in the example mentioned in the link above:
> from django.contrib.flatpages import views
> urlpatterns += [
>     url(r'^about-us/$', views.flatpage, {'url': '/about-us/'}, name='about'),
>     url(r'^license/$', views.flatpage, {'url': '/license/'}, name='license'),]

You can use the cache_control view decorator to wrap the flatpage view
before you plug it into your urlpatterns::

    from django.contrib.flatpages import views
    from django.views.decorators.cache import cache_control

    cached_flatpage = cache_control(max_age=4700)(views.flatpage)

    urlpatterns += [
        url(r'^about-us/$', cached_flatpage, {'url': '/about-us/'}, name='about'),
        url(r'^license/$', cached_flatpage, {'url': '/license/'}, name='license'),]



You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment