Django
from django.utils.http import urlquote
response.set_cookie('name', urlquote(username))
JS
getCookie (name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return (arr[2]);
else
return null;
}
console.info(decodeURI(getCookie ('name') ))