title: Session data is not getting updated - decoding the session key
body: <p>Need help with a Django related doubt.
  I've been trying to develop an ecommerce webapp using Django. When I try to get the session data after clicking on 'Add to Basket' it shows the response from the 'init' method and not the 'add' method.</p>
  <p>This is the button:</p>
  <pre><code>          &lt;button type=&quot;button&quot; id=&quot;add-button&quot; value=&quot;{{product.id}}&quot; class=&quot;btn btn-secondary btn-sm&quot;&gt;Add to Basket&lt;/button&gt;
  </code></pre>
  <p>Ajax Script:</p>
  <pre><code>          &lt;script&gt;
                $(document).on('click', '#add-button', function (e) {
                    e.preventDefault();
                    $.ajax({
                        type: 'POST',
                        url: '{% url &quot;basket:basket_add&quot; %}',
                        data: {
                            productid: $('#add-button').val(),
                            csrfmiddlewaretoken: &quot;{{csrf_token}}&quot;,
                            action: 'post'
                        },
                        success: function (json) {
  
                        },
                        error: function (xhr, errmsg, err) {}
                    });
                })
            &lt;/script&gt;
  </code></pre>
  <p>View.py file:</p>
  <pre><code>          from django.shortcuts import render
            from django.shortcuts import get_object_or_404
            from django.http import JsonResponse
            from store.models import Product
            from .basket import Basket
  
            def basket_summary(request):
                return render(request, 'store/basket/summary.html')
  
            def basket_add(request):
                basket = Basket(request)
                if request.POST.get('action') == 'post':
                    product_id = int(request.POST.get('productid'))
                    product = get_object_or_404(Product, id=product_id)
                    basket.add(product=product)
                    response = JsonResponse({'test':'data'})
                    return response
                
  </code></pre>
  <p>urls.py file:
  from django.urls import path</p>
  <pre><code>          from . import views
  
            app_name = 'basket'
            urlpatterns = [
                path('', views.basket_summary, name='basket_summary'),
                path('add/', views.basket_add, name='basket_add'),
            ]
  </code></pre>
  <p>Basket Class:
  class Basket():</p>
  <pre><code>              def __init__(self, request):
                    self.session = request.session
                    basket = self.session.get('skey')
                    if 'skey' not in request.session:
                        basket = self.session['skey'] = {}
                    self.basket = basket
  
                def add(self, product):
  
                    product_id = product.id
  
                    if product_id not in self.basket:
                        self.basket[product_id] = {'price': str(product.price)}
  
                    self.session.modified = True    
                    
  </code></pre>
  <p>context_processors.py</p>
  <pre><code>            from .basket import Basket
  
  
              def basket(request):
                  return {'basket': Basket(request)}
                  
  </code></pre>
  <p>Also added this to the templates.</p>
  <p>When I try to decode it</p>
  <p>s= Session.objects.get(pk='uomjko48iiek9er7jw1gah2ayrvoc5pv')</p>
  <p>s.get_decoded()</p>
  <p>I get {'skey': {}} and not the product ID and the price.</p>