AP257
AP257

Reputation: 93813

Django: don't cache particular view?

As per the title...

Is there a way I can force a particular view (actually a particular JSON-formatted set of results, that will be served to Ajax queries) NEVER to cache in Django?

Thanks!

Upvotes: 3

Views: 2513

Answers (2)

Hipikat
Hipikat

Reputation: 145

To be sure, decorate it with @never_cache:

from django.views.decorators.cache import never_cache

@never_cache
def myview(request):
    # ...

As in The per-view cache documentation.

Upvotes: 9

Reto Aebersold
Reto Aebersold

Reputation: 16624

Django does not cache views unless you specify a per-view cache.

If you have problems with (cached) Ajax responses, try to add a timestamp to your URL:

e.g. /my_view?ts=23432453453

So you can be sure that your browser does not cache the Ajax responses.

Upvotes: 0

Related Questions