python - Django - request.session not being saved -
i have pretty utility function gets open web order if session key called 'orderid', , create 1 if there no session key, , parameter 'createifnotfound' equal true in function. stepping through debugger can see piece of code sets session key after order has been created hit no exceptions, when check http request object' session field, not have attribute ?
utility
def get_open_web_order(request, createifnotfound=false): # check orderid in session order_id = request.session.get('orderid') web_order = none if none != order_id: try: web_order = weborder.objects.get(id=order_id, status='o') logging.info('found open web order') except weborder.doesnotexist: logging.info('web order not found') if (none == web_order) , (createifnotfound == true): logging.info('creating new web order') web_order = weborder() web_order.status = 'o' web_order.save() request.session['orderid'] = web_order.id # assign logged in user , default billing , shipping if request.user.is_authenticated() , hasattr(request.user, 'customer'): customer = request.user.customer web_order.customer = customer web_order.set_defaults_from_customer() web_order.save() return web_order
in cases need explicitly tell session has been modified.
you can adding request.session.modified = true
view, after changing in session
you can read more on here - https://docs.djangoproject.com/en/1.10/topics/http/sessions/#when-sessions-are-saved
Comments
Post a Comment