0

I don't understand clearly why the URL is not calling a function,instead it returns old information. May be cache problem ? If yes, how to prevent ?

Please note: I am using render_to_response

The cases I have tried is REQUEST METHOD : GET or I am refreshing the browser for the new information

Is anyone facing the same issue before ? please let me know your views. Your help is highly appreciable

For instance:

URLS.PY

url(r'^home/$','home.views.index')

VIEWS.PY

def index(request):
    print "I am in index"
    new_info = "Here getting updated information from django models"
    return render_to_response('index.html',{'new_info':new_info})

Problem is some times it goes inside the function and returns new information, but other times not at all going inside, instead returns old information

More info: if the function calls then returns new information, if not it returns old information For instance: I called index function first time, then It returns ONE, second time calling, it returns SECOND. My case is some times am getting TWO or THREE, the fact is I have to get SIX

user2224250
  • 251
  • 1
  • 8
  • 19
  • Could you explain more on what is old information? Is the data dynamically generated? – Nagaraj Tantri May 06 '15 at 05:25
  • possible duplicate of [django: return string from view](http://stackoverflow.com/questions/24817007/django-return-string-from-view) – Nagaraj Tantri May 06 '15 at 05:26
  • @LearningNeverStops Let us assume, if the function calls then returns new information, if not he will get old information For instance: I called index function first time, then It returns ONE, second time calling, it returns SECOND. My case is some times am getting TWO, the fact is I have to get FIVE or SIX – user2224250 May 06 '15 at 05:28
  • Are you saying you are able to return just the string from a view? I recall having always returning a `HttpResponse` – Nagaraj Tantri May 06 '15 at 05:32
  • Try `@never_cache` before the view. – Nagaraj Tantri May 06 '15 at 05:38
  • Thanks. I will check all the cases. I believe, this should be the way to prevent cache..btw, for class based views where to add @never_cache decorator, since i am only one function i.e. get_context_data – user2224250 May 06 '15 at 05:46
  • This should give you a clue, either put for urls.py or directly to class. https://docs.djangoproject.com/en/1.8/topics/class-based-views/intro/#decorating-class-based-views – Nagaraj Tantri May 06 '15 at 06:10

1 Answers1

0

Add a url parameter such as:

www.example.com/?time_now=12334456678

The UTC timestamp will always be different and hence force a fresh uncached response to be generated.

andrea-f
  • 1,045
  • 9
  • 23