Ошибка при выводе списка подписчиков пользователя
Я пытаюсь добавить функцию уведомлений к своей платформе социальных сетей. Частично это включает в себя добавление логотипа уведомлений на мою навигационную панель в верхней части моего сайта, который будет отображать количество непросмотренных уведомлений у вошедшего пользователя.
Когда я запускаю свой сервер, я получаю NameError:
Вот часть моего navbar.html:
{% load custom_tags %}
(...)
{% if user.is_authenticated %}
<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle text-dark" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false"><i class="fas fa-user"></i></a>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="{% url 'profile' request.user.profile.pk %}">Profile</a></li>
<li><a class="dropdown-item" href="{% url 'account_logout' %}">Sign Out</a></li>
</ul>
</div>
<div class="nav-item">
{% show_notifications %}
{% endif %}
</div>
</div>
</nav>
Вот мой show_notifications.html:
<div class="dropdown">
<span class="badge bg-primary notification-badge">{{ notifications.count }}</span>
<div class="dropdown-content d-none" id="notification-container">
{% for notification in notifications %}
{% if notification.post %}
{% if notification.notification_type == 1 %}
<div class="dropdown-item-parent">
<a href="#">@{{ notification.from_user }} liked your post</a>
<span class="dropdown-item-close">×</span>
</div>
{% elif notification.notification_type == 2 %}
<div class="dropdown-item-parent">
<a href="#">@{{ notification.from_user }} commented on your post</a>
<span class="dropdown-item-close">×</span>
</div>
{% endif %}
{% elif notification.comment %}
{% if notification.notification_type == 1 %}
<div class="dropdown-item-parent">
<a href="#">@{{ notification.from_user }} liked on your comment</a>
<span class="dropdown-item-close">×</span>
</div>
{% elif notification.notification_type == 2 %}
<div class="dropdown-item-parent">
<a href="#">@{{ notification.from_user }} replied to your comment</a>
<span class="dropdown-item-close">×</span>
</div>
{% endif %}
{% else %}
<div class="dropdown-item-parent">
<a href="#">@{{ notification.from_user }} has started following you</a>
<span class="dropdown-item-close">×</span>
</div>
{% endif %}
{% endfor %}
</div>
</div>
Вот мой custom_tags.py:
from django import template
from academiciesocial.models import Notification
register = template.Library()
@register.inclusion_tag('social/show_notifications.html', takes_context=True)
def show_notifications(context):
request_user = context['request'].user
notifiations = Notification.objects.filter(to_user=request_user).exclude(user_has_seen=True).order_by('-date')
return {'notifications': notifications}
Конечная notifications была помечена как "не определена (PylancereportUndefinedVariable)".
Мой класс уведомлений из моего models.py:
class Notification(models.Model):
# 1 = Like, 2 = Comment, 3 = Follow
notification_type = models.IntegerField()
to_user = models.ForeignKey(User, related_name='notification_to', on_delete=models.CASCADE, null=True)
from_user = models.ForeignKey(User, related_name='notification_from', on_delete=models.CASCADE, null=True)
post = models.ForeignKey('Post', on_delete=models.CASCADE, related_name='+', blank=True, null=True)
comment = models.ForeignKey('Comment', on_delete=models.CASCADE, related_name='+', blank=True, null=True)
date = models.DateTimeField(default=timezone.now)
user_has_seen = models.BooleanField(default=False)
Я довольно новичок в этом, поэтому буду очень признателен за точные пошаговые ответы на проблему :)
