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:
- 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, returnorder_no
value. - session: store order_no in session. assume had earlier view value
order_no
set, @ point save usingrequest.session['order_no']=order_no
. later, when wanted retrieve value, useorder_no=request.session['order_no']
in view. - 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 cookieresp.set_cookie("order_no", order_no)
. retrieve usingrequest.cookies['order_no']
there other, bizarre, places store value: files, cache, other data storage formats, etc. not @ recommended.
Comments
Post a Comment