locals() 在django中间的一处妙用
locals() 在django当中的一处妙用从django的manual 当中看到的def current_datetime(request):current_dat
locals() 在django当中的一处妙用
从django的manual 当中看到的
def current_datetime(request): current_date = datetime.datetime.now() return render_to_response('current_datetime.html', locals()) 而且,
虽然locals()返回的是一份拷贝,但是依然可以往里面赋值,就像使用map一样,l = locals()
l["x"] = 111
l["y"] = 222
尽管不能print x,print y, 但是
需要的时候调用那个假的x,或者y的时候, 写上locals()就行比如print locals(),就能看到x,y了