我有这个错误:
全局名称'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
答案 0 :(得分:1)
我想你的意思是request.user
ecredit = UserEarned.objects.get(user=user)
# ^^^^ here