But I need to do it:

**ok I try to explain better my situation**:

- I've got a class that is a "javascript repository". Its role is to 
respond with a string of javascript functions.  
Javascript functions are organized in indipendent modules (list of 
functions), so I can attach to my page just needed functions.  
Different modules can share same functions.
- In my view I specify the url of a function (it is in the same view), 
get_js_code, whose rule is to return javascript code (with: `return 
HttpResponse(code,content_type="application/x-javascript")` )
- get_js_code initiate that "javascript repository class", asking one or 
more modules (list of functions), and my class returns functions just one 
time, even if a function belongs to more than one module.  
- in my template I specify get_js_code url as a javascript resource, and 
javascript code is downloaded with the page from Django

It works well _BUT_:

- a module is needed from every app, so I specify in a Middleware an url 
that brings to another app/function that initiate that class in order to 
attach as javascript resource the common javascript module.

**Here is the problem**:

- my "javascript repository class" has a list that contains returned 
javascript functions list in order to return a function just one time. It 
works well but just one time: infact if I reload the page the list does not 
expire and no javascript funtions are returned.

Very hard to explain, I hope its clear now.

PS: I was wrong, I don't initiate the class inside a Middleware.

PPS: I know that is unusual to put javascript code inside Python code, but 
I'm testing this solution.


Il giorno giovedì 16 aprile 2015 12:36:39 UTC+2, Avraham Serour ha scritto:
>
> you are instantiating the variable on class definition, try doing on 
> function execution instead
>
> On Thu, Apr 16, 2015 at 12:43 PM, Silvio Benvegnù <silvio...@gmail.com 
> <javascript:>> wrote:
>
>> I'm using Django Framework 1.7 with its webserver.
>>
>> I have a custom class where I declare a static variable, a list, where I 
>> append some values:
>>
>> class my_class:
>>
>>     list = [] 
>>
>>     def __init__( self, *args, **kwargs ): 
>>         [...]
>>
>>     def append_value(self,value):
>>         self.list.append( value )
>>
>> I use a static variable because I call this function different times. 
>> During a single page load my class works well but I noticed that 
>> my_class.list never expire.
>>
>> To reset the list I have to restart the webserver.
>>
>> I come from PHP and Perl where every time you refresh a page all yor 
>> variables are cleared if you don't save them in some way.
>>
>> I use session, sure, but I don't save that list into session, at least 
>> not voluntarily.
>>
>> NOTE: I don't know, during script execution, the first or the last time I 
>> call my_class().
>>
>> How can I reset the list every time I reload/change page?
>>
>>  -- 
>> 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...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> 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/f7f81ae7-8c33-49e8-8781-86c4c5cd2edb%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/f7f81ae7-8c33-49e8-8781-86c4c5cd2edb%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/7e80cb8e-55dc-4123-9839-ee692ce340c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to