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?

Thanks.

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):
>
> https://docs.djangoproject.com/en/1.10/ref/contrib/flatpages/
>
> 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'),]

Cheers,

Michal

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6d9d04ee-1bce-4031-89ea-823c52e8438d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment