首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

locals() 在django中间的一处妙用

2013-01-23 
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了

热点排行