python---补充locals()变量在变量分发中的使用

在Django,tornado等框架中,变量分发渲染模板是一件再平常不过的事,但是当变量过多时,如何快速的进行变量传递

此时就可以用到locals()获取本地变量,将变量变为字典传入

def introduce(req):
    ala= 'dfasfa'
    fas='fsa'
    print(locals())
    #{'fas': 'fsa', 'req': <WSGIRequest: GET '/blog/%20news/story'>, 'ala': 'dfasfa'}
    return HttpResponse("<h1>ok你</h1>")
原文地址:https://www.cnblogs.com/ssyfj/p/8642241.html