Как получить профиль вошедшего пользователя в context_processors.py Django?
У меня есть context_processors.py для отображения дополнительной информации в base.html. Мне нужно получить request.user, чтобы получить его профиль и показать все сообщения пользователя в news.html. Когда я делаю profile = Profile.objects.filter(user=request.user.id)
, Django показывает, что ни один пользователь не соответствует данному профилю, когда я выхожу из системы. Как мне это исправить?
context_processors.py
from users.models import Profile
def notification_to_base(request):
counter = 0
profile = Profile.objects.filter().first() # I'm getting Admin_profile, but I need to get a logged in user profile
subscribing = profile.subscribing.filter() # TestUser, TestUser_two
for following in subscribing:
posts = following.post_set.filter(is_checked=False) # post № 1, post № 2
for post in posts:
counter += 1
return {'answers': answers, 'counter': counter}