简体   繁体   中英

how to execute the output of print statement in python?

def BeersAll(request):
    print request.COOKIES
    attrib_list = dir(request)
    print attrib_list
    xyz = 'request.'+str(attrib_list[0])
    print xyz
    beers = Beer.objects.all().order_by('name')
    context = {'beers': beers}
    return render_to_response('index.html', context, context_instance=RequestContext(request))

output:

  1. {'csrftoken': 'oXhz3P8qcAfTfz0f6KjU9QivGi4wReNe', 'sessionid': 'bwavmmrlquwusixnrvp6hjzbzy2pdly5'}

  2. ['COOKIES', 'FILES', 'GET', 'META', 'POST', 'REQUEST', ....]

  3. request.COOKIES

I am trying to loop through the attrib_list and execute all items (ie) request.items)

I am looking for the kind of output i got for request.COOKIES in first line for all other attributes, is there any way to accomplish this in python.

req_data = {'request': []}
for attr in attrib_list:
    req_data['request'].append(attr)

and render it to templates. but I dont understand why you would need this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM