Wednesday 15 February 2012

How can I get the lenth of a session in django views -


I am using code for my wish list. There is no need for products in the wish list to show me there on my site. I tried many ways but I think the session can only do this. Can some help please

How can I do this?

  @never_cache def Wishlist (request, template = "store / wish list html"): "" "Display the wish list and handle the items from wishlist and add them to the cart. " "Skus = request.wishlist error = nobody does, request.method ==" post ": to_cart = request.POST.get (" add_cart ") add_product_form = AddProductForm (request.POST or none, to_cart = to_cart, Request = request) if to_cart: if add_product_form.is_valid (): request.cart.add_item (add_product_form.variation, 1, request) recalculate_discount (request) message = _ url = "shop_cart" and ("add item to cart"): Error = add_product_form.errors.values ​​() [0] Some: Message = _ ("Excluded from item wish list") url = "shop_wishlist" sku = request.POST.get ("sku") If sku in SKUs: Skus.remove (SKU) Otherwise error: information (request, message) response = Redirect (URL) set_cookie (feedback, "wish list", ",".) Join (score) Return response # Remove the scoose from the cookie that no longer exists. Published_products = Product.objects.published (for_user = request.user ) F = {"product__in": published_products, "sku__in": SKUs} wish list = ProductVariation.objects.filter (** f) .select_related (depth = 1) wish list = solve (wishlist, key = lambda v: skus .index (v.sku)) reference = {"wishlist_items": wishlist, "error": error} response = submission (request, template, reference) if l EN (included in the wish list) & lt; Take (Skooze): Scoops = [variation.sku for change in wishlist] set_cookie (feedback, "wishlist", ",".) Join (sc)) Return response    

session! Cookies are managed by the server on the session backend, cookies are sent to the user browser. But you are just using cookies in this example.

The session structure allows you to store and retrieve arbitrary data on a per-site visitor basis. It stores data on server side and presents the essence of sending and receiving cookies. Cookies have a session ID ??? Not the data itself (unless you are using cookie based backend).

It's hard to say what you want, but if you want to count only the number of items you are saving in the cookie, then you just have your sku < / Code> and will be sent in context template:

  if len (wishlist) & lt; LINU (SKUs): SKUs = set_cookie [variation.sku for change in wish list]. (., "Wishlist", "," join in (SKUs)) reference = {"wishlist_items": wishlist, "error ": Error," wishlist_length <: <{   

and use:

in your template

No comments:

Post a Comment