Friday, November 7, 2014

Re: Django strange behaviour

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

--
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+unsubscribe@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/CF469FF4-BDD9-4925-BEC5-DE3A1142AA35%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment