Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

277
Views
WSGIRequest' object has no attribute 'session_key

enter image description here

I am getting this error when i try to access the session I am not able to understand why it is not understanding what is session it is in installed apps it knows what is session

def _cart_id(request):
    cart = request.session_key
    if not cart:
        cart = request.session.create()
    return cart

def add_cart(request,id):
    prod = Product.objects.get(id = id)
    try:
        cart = Cart.objects.get(cart_id = _cart_id(request))

    except Cart.DoesNotExist:
        cart = Cart.objects.create(
            cart_id = _cart_id(request)
        )
    cart.save()

    try:
        cart_item = CartItem.object.get(product = prod,cart = cart)
        cart_item.quantity += cart_item.quantity
    except CartItem.DoesNotExist:
        cart_item = CartItem.objects.create(
            product = prod,
            quantity = 1,
            cart = cart, 
        )
        cart_item.save()

    return redirect('/shop/') 
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The request object has no session_key but session. And session_key is inside session. Then :

def _cart_id(request):
    # Not request.session_key but request.session.session_key
    cart = request.session.session_key
    if not cart:
        cart = request.session.create()
    return cart
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!