title: using django session inside templates
body: <pre><code># 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
  </code></pre>
  
  <p>I am using <code>context_instance = RequestContext(request)</code> so that session variable is available, while rendering response. My template:</p>
  
  <pre><code>{% if request.session.restaurants.rest.id.food_like %}
  working
  {% else %}
      failed
  {% endif %}
  </code></pre>
  
  <p>My view session key looks like this :</p>
  
  <pre><code>request.session["restaurants"][restaurant][like] = True
  </code></pre>
  
  <p>where <code>restaurant</code> is the restaurant id, and like could be one of " "food_like", "service_like", "special_like".</p>
  
  <p>So how am i supposed to access it in my templates? For example if i use </p>
  
  <pre><code>request.session.restaurants.rest.id.food_like 
  </code></pre>
  
  <p>it won't work for sure.</p>