Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

Friday, August 20, 2010

Django cache (storage)

If you need to store something useful between client requests, you can use Django cache framework.

It allows you to use memory, file, database or custom storage type.

Its using is very simple:

Add CACHE_BACKEND = 'locmem://' in settings to use memory cache

Import cache: "from django.core.cache import cache" in .py file.
Get value: cache.get('stored_data'). It returns None if there is no 'stored_data'.
Set value: cache.set('stored_data', my_data, 60). '60' is optional - timeout of cache expiration.
Delete value: cache.delete('stored_data')

Wednesday, April 7, 2010

Django sessions and forms in IE


Django framework allows to store user data in the current browser session.

Each HttpRequest request has session attribute which is dictionary-like object:
request.session['context'] = '2k3'

But keep in the mind that this operation changes current session and it can affect the browser behaviour.

For instance, Internet Explorer enforces page refreshing during previous page loading by "Back"operation. So if you had completed form there (on the previous page) - form's data is lost with "Back" in browser.