Django: not cache a specific view?

According to the name ...

Is there a way to force a particular view (actually a specific set of results in JSON format to be served for Ajax requests) NEVER cache in Django?

Thank!

+3
source share
2 answers

Of course, decorate it @never_cache:

from django.views.decorators.cache import never_cache

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

As in the documentation for each window .

+9
source

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

If you are having problems with (cached) Ajax responses, try adding a timestamp to the url:

e.g.. / My_view? C = 23432453453

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

0
source

Source: https://habr.com/ru/post/1792747/


All Articles