[Django]-Is that possible to cache django flatpages?

2👍

Yes, just cache your site as normal and make sure that FetchFromCacheMiddleware is before FlatpageFallbackMiddleware. In this case, caching doesn’t need to be done on the application level.

1👍

Better way to do this is just cache flatpage views (not cache all views!)

I recommend something like this:

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

urlpatterns = [
    url(r'^pages/(?P<url>.*)$', cache_page(60 * 60)(views.flatpage), name='django.contrib.flatpages.views.flatpage'),
    # other routes here ...
    ]

Leave a comment