Adds the user attribute, representing
the currently-logged-in user, to every incoming HttpRequest object.
See Authentication in Web requests.
源代码(django.contrib.auth公司.中间件.py)地址:
class AuthenticationMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
request.user = SimpleLazyObject(lambda: get_user(request))
确保您正在使用^{} 。否则
user
在模板中不可用。你知道吗在
AuthenticationMiddleware
里。你知道吗官方文件提到:
link:
link:
源代码(django.contrib.auth公司.中间件.py)地址:
相关问题 更多 >
编程相关推荐