I have a view in Django which calls external library/class. The problem is 
that for some reason Django keeps caching results coming from previous 
calls of that class.

Please consider the following simple example:

Django view:

from some_path import Demodef test_view(request):
    demo = Demo()
    result = demo.do_something()
    return render(request, 'test.html',
                            { 'result':result }
                )

Demo class:

class Demo():
    result = []

    def do_something(self):
        self.result.append(1)
        self.result.append(2)
        self.result.append(3)
        return self.result

You expect result to be [1, 2, 3], right ? WRONG!

The first time a page is loaded you'll get the correct result. But on all 
following requests it will keep incrementing: [1, 2, 3, 1, 2, 3]... [1, 2, 
3, 1, 2, 3, 1, 2, 3] ...

So my question is obvious - what is going on here ? How do i receive [1, 2, 
3] every time i call a class inside Django view ?

p.s. - Django 1.7 / MacOSx

-- 
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/72ee993f-cc34-4aee-9455-694b09148d8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to