Re: Django strange behaviour

16 views
Skip to first unread message

Erik Cederstrand

unread,
Nov 7, 2014, 4:32:22 AM11/7/14
to Django Users

> Den 07/11/2014 kl. 10.08 skrev termopro <term...@gmail.com>:
>
> 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.

This is expected Python behaviour - see https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables

To start with an empty result list on every class instantiation, you need to stick it into __init__:

class Demo():
def __init__(self):
self.result = []

def do_something(self):
self.result.append(1)


Erik
Reply all
Reply to author
Forward
0 new messages