On Saturday, 3 October 2015 02:25:46 UTC+5:30, Andréas Kühne wrote:
Hi,I don't think you can reliably do that. Django never knows when the user closes his browser window. Because a session is stateless (there is only a connection to the server when it responds to a request). However you could do this via a bit of ajax or a pretty unreliable javascript event.What I would do is to ping the server via javascript once every minute or so - you then update a timestamp on a session object or the user model or something like that. Then if the timestamp is older than 5 minutes, you can safely delete the temporary files.Another way would be to add an event handler to the onbeforeunload event, see http://stackoverflow.com/questions/20853142/trying-to- . When the event fires, you just fire an ajax call to your server that deletes the files.detect-browser-close-event HOWEVER, I know that this doesn't always fire and can be a bit tricky. But it's worth a shot.Regards,Andréas
I made following assumption that I can do that on the base that their where function related to sessions like get_expiry_age(), get_expire_at_browser_close() using which I could do what it thought.
What you told I completly understand but what I am not to understand that where should I write that background code or how to trigger that function automatically when timestamp get older than some min (as you suggested ) ,which is my basic question for this thread.
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/7eb1beec-9c7d-4d7f-b53d-525e59493f41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment