Django Evercookie is an implementation of [Evercookie] (http://en.wikipedia.org/wiki/Evercookie) with Django backend services. Evecrookie core component was rebuilt to use of Django's batteries, so all configurations and hook-ups are done in plain Python and Django's templatetags.
Note: Django 1.5 or later required.
The project hasn't been maintained for quite some time. Afaik later Django versions have some API changes that require the backend to be modified. If you want to contribute to the project and keep it up to date, please send pull requests.
Client browsers must support as many of the following storage mechanisms as possible in order for Evercookie to be effective.
- Standard HTTP Cookies
- Flash Local Shared Objects
- CSS History Knocking
- Storing cookies in HTTP ETags
- Storing cookies in Web cache
- window.name caching
- Internet Explorer userData storage
- HTML5 Session Storage
- HTML5 Local Storage
- HTML5 Global Storage
- HTML5 Database Storage via SQLite
- HTML5 Canvas - Cookie values stored in RGB data of auto-generated, force-cached PNG images
- HTML5 IndexedDB
- [Django Don't Vary On] (https://github.com/rory/django-dont-vary-on)
Is used to turn off Vary HTTP headers for some views because Django adds this headers automatically if Auth and Session middlewares are used.
- [Python Imaging Library] (http://www.pythonware.com/products/pil/)
To generate PNG cookies.
- Install Python Egg
pip install git+https://github.com/gdmka/django_evercookie.git#egg=django-evercookie
- Add Django Evercookie to INSTALLED_APPS
INSTALLED_APPS += ('django_evercookie',)
- Add RemoveUnneededVaryHeadersMiddleware at the top of MIDDLEWARE_CLASSES in settings.py:
MIDDLEWARE_CLASSES = (
'django_dont_vary_on.middleware.RemoveUnneededVaryHeadersMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
...
)
- Add routing in urls.py
urlpatterns += patterns('', ('', include('django_evercookie.urls')),)
Sometimes you need to configure things your way. Some snippets of configuring Django Evercookie.
from django_evercookie.config import settings
#Changing cookie names for Etag storage
settings.etag_cookie_name = 'etagstorage'
#Enabling CSS History Knocking
settings.history = 'true'
#Setting Django's STATIC_URL manually
settings.static_url = '/cdn/'
Add this code to load evercookie in template and set a value.
{% load staticfiles %}
<script src="{% static 'django_evercookie/swfobject-2.2.min.js' %}"></script>
<script src="{% url 'django_evercookie.views.evercookie_core' %}"></script>
{% load evercookie_js_api %}
{% set_evercookie ec_obj='evercookie' name='dummy' value='some_value' %}
This will load evercookie core library and render set method.
<script>
var evercookie=new evercookie();
evercookie.set("dummy", "some_value");
</script>
The get method is as simple as adding
{% rediscover_evercookie ec_obj='evercookie' name='dummy' %}
to discover what was set in previous snippet.
Evercookie was developed by Samy Kamkar, with contributions from others
MIT