上下文预处理程序 - 未定义全局名称“user”

时间:2013-07-05 05:46:05

标签: django

我有这个错误:

  

全局名称'user'未定义

我做错了什么以及如何纠正?

context_processors.py

from content.models import *
from django.contrib.auth.models import User

def your_earned(request):
    if request.user.is_authenticated():
        ecredit = UserEarned.objects.get(user=user)
        if ecredit.exists():
            return {'ecredit': ecredit}
        else:
            ecredit = '0'
            return {'ecredit':ecredit}
    else:
        pass

1 个答案:

答案 0 :(得分:1)

我想你的意思是request.user

ecredit = UserEarned.objects.get(user=user)
#                                     ^^^^ here