python 中locals()的应用

def login(request):
    if request.method == 'POST':
        user = request.POST.get('user')
        pwd = request.POST.get('pwd')

        if user == 'aaa' and pwd == 'xxxx':
            return redirect('publisher')
        else:
            error = '用户名密码错误'

    return render(request, 'login.html', locals())

locals() 取的是 login() 函数中的变量;并且返回的是一个字典;

posted @ 2021-08-13 18:26  Star-Hitian  阅读(161)  评论(0编辑  收藏  举报