Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ContextList keys

Is there a way to get the keys of a returned ContextList object when running a test harness?

If I have:

return render_to_response('x.html', 
                              {
                               'one' : 1,
                               'two' : 2,
                               'three' : 3
                               },
                              context_instance=RequestContext(request)) 

Is there a way to loop through the keys one, two, & three?

like image 870
Trent Avatar asked Oct 30 '25 02:10

Trent


1 Answers

keys = []
for subcontext in response.context:
  for d in subcontext.dicts:
    for k in d.keys():
      if k not in keys:
        keys.append(k)

print keys
like image 105
PizzaPanther Avatar answered Nov 01 '25 17:11

PizzaPanther



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!