# views.py def like(request,option="food",restaurant = 1): if request.is_ajax: like = '%s_like' % str(option) if 'restaurants' in request.session: if restaurant not in request.session['restaurants']: request.session['restaurants'][restaurant] = {} x = request.session['restaurants'][restaurant].get(str(like),False) if x: return HttpResponse(False) else: request.session['restaurants'][restaurant][str(like)] = True request.session.modified = True else: request.session['restaurants'] = {} request.session.modified = True
I use context_instance = RequestContext(request) so that the session variable is available instead of rendering. My template:
{% if request.session.restaurants.rest.id.food_like %} working {% else %} failed {% endif %}
My browsing session is as follows:
request.session["restaurants"][restaurant][like] = True
where restaurant is the identifier of the restaurant, and, as it may be, one of "food_like", "service_like", "special_like".
So, how should I access it in my templates? For example, if I use
request.session.restaurants.rest.id.food_like
it will not work for sure.
source share