Note that there are some explanatory texts on larger screens.

plurals
  1. POdefining django session keys dynamically
    primarykey
    data
    text
    <h1>urls.py</h1> <pre><code>(r'^(?P&lt;restaurant&gt;\d+)/like/(?P&lt;option&gt;\w+)$','like') </code></pre> <h1>views.py</h1> <pre><code>def like(request,option="food",restaurant = 1): if request.is_ajax: rest = 'rest' #option could be 'food' , 'service' , 'speciality' like = '%s_like' % str(option) if restaurant in request.session: if like not in request.session[restaurant]: request.session[restaurant][str(like)] =str(like) session = [item for item in request.session[restaurant]] return HttpResponse(session) else: session = [item for item in request.session[restaurant]] return HttpResponse(session) if restaurant not in request.session: request.session[restaurant] = {} </code></pre> <h1>html</h1> <pre><code>&lt;a href="/{{rest.id}}/like/{{key|lower}}"&gt; &lt;button data-placement="left" data-original-title="{{val.0}} people like {{key|upper}} at {{rest|title}}" rel="tooltip" class="like pull-right pointer btn btn-info text-left pad0 btn-mini mrg-left5 like-food"&gt; &lt;i class="icon-thumbs-up"&gt;&lt;/i&gt;&amp;nbsp;{{val.0}} &lt;/button&gt;&lt;/a&gt; </code></pre> <p>here rest.id = 1</p> <h1>doubt</h1> <p>i am not able to understand when i declared 'restaurant' key as a dictionary then , when i click on the like button its not returning all the keys , every time only one key is returned , for example when i click the food_like button , its returning the key food_like but then again when i click on service_like button instead of returning all food_like and service like its just returning service like , please help. thanks in advance</p> <p>basically what i want is to create nested session dictionary ,for eg.</p> <pre><code>request.session[restaurant][food][like] request.session[restaurant][food][dislike] request.session[restaurant][service][like] request.session[restaurant][service][dislike] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload