Re: How can you use the @cache_page decorator with Django class based views?

2015-11-14 Thread Simon Charette
Hi Daniels,

There's a tentative API being worked on Github. You might want to have a 
look at it .

Simon

Le samedi 14 novembre 2015 13:38:18 UTC-5, daniels a écrit :
>
> The only method that seems to be working is adding the decorator in 
> urls.py which is ugly.
>
> Is there any way to apply this decorator in the view?
>
> class HomeView(View):
> @method_decorator(cache_page(60 * 60))
> def dispatch(self, *args, **kwargs):
> return super(HomeView, self).dispatch(*args, **kwargs)
>
> I've tried the above but it doesn't seem to be working. I've also tried 
> adding it to the get method (which is what I want to cache).
>
> I'm using FileBasedCache and only when I use cache_page decorator in 
> urls.py I see files being created in my cache folder. With the method above 
> nothing happens.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b3fe1d73-a06d-4007-9fe4-83adf7ba2d14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How can you use the @cache_page decorator with Django class based views?

2015-11-14 Thread daniels


The only method that seems to be working is adding the decorator in urls.py 
which is ugly.

Is there any way to apply this decorator in the view?

class HomeView(View):
@method_decorator(cache_page(60 * 60))
def dispatch(self, *args, **kwargs):
return super(HomeView, self).dispatch(*args, **kwargs)

I've tried the above but it doesn't seem to be working. I've also tried 
adding it to the get method (which is what I want to cache).

I'm using FileBasedCache and only when I use cache_page decorator in 
urls.py I see files being created in my cache folder. With the method above 
nothing happens.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ef695b71-5bcf-4fa7-b3e0-6b622ad8bab5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.