templates - Django want to use a variable from another view -


i have list of items in view called client_items. want able use variable items_list`which view called edit_order in client_items. there way call variable different view? (import variable view , able use variable in other) cannot write in client_items view because needs order_no augment.

edit: here latest views. have tried creating views called items_in_edit_order. @ point `order_no not defined.

    def items_in_edit_order(order_no):         order = models.order.objects.get(pk = order_no)         return order  def client_items(request, client_id = 0):     client = models.client.objects.get(pk = client_id)     items = client.storageitem_set.all()     order = items_in_edit_order(order_no)     return render_to_response('items.html', {'items':items, 'client':client, 'order':order}, context_instance = requestcontext(request)) 

just adding, since no 1 has said , seems don't understand yet:

your client_items view must, somehow, have access order_no variable. if reason value not being passed along via url, must value somehwere. there 3 real locations value:

  1. database: work if are, example, storing cart directly linked user. example, might able order_no = order.objects.filter(cart__user=request.user).order_no order associated user's current cart, return order_no value.
  2. session: store order_no in session. assume had earlier view value order_no set, @ point save using request.session['order_no']=order_no. later, when wanted retrieve value, use order_no=request.session['order_no'] in view.
  3. cookie: not recommended, option nonetheless. it's complicated because in first view you'd have create response object (as in resp = render_to_response(template_name, locals(), requestcontext(request)) , then write cookie resp.set_cookie("order_no", order_no). retrieve using request.cookies['order_no']

there other, bizarre, places store value: files, cache, other data storage formats, etc. not @ recommended.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -