problem in navbar

this code is for navigation bar in my website. when a new notification comes the var has_new_notification will be true
then the notification-mark should show in notification element in the navbar. also there is class called active that makes the element color in navbar change when i click on the element. the problem: i can only see the notification-mark on notification element when i am inside notification page.

{% load static %}

<style>
  
  .header__menuItem.active a{
  background-color: #51546e;
  color: #fff;
  padding: 10px 20px;
  margin: -10px -20px;
  border-radius: 10px;
}


.header__menuItem.notification {
    position: relative;
  }

  .notification-mark {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background-color: red;
    border-radius: 50%;
  }

 


</style>

<!-- Header Section -->
<header class="header" >
    <div class="container container--narrow">
      <a href="" class="header__logo">
        <img src='{% static "images/logo.png" %}' alt="DevSearch Logo" />
      </a>
      <nav class="header__nav">
        <input type="checkbox" id="responsive-menu" />
        <label for="responsive-menu" class="toggle-menu">
          <span>Menu</span>
          <div class="toggle-menu__lines"></div>
        </label>
        <ul class="header__menu">
          
          {% if request.user.is_authenticated and request.user.is_Seeker %}
          <li class="header__menuItem "><a href="{% url 'SeekerHome' %}">Home</a></li>
          <li class="header__menuItem"><a href="">Activites</a></li>
          <li class="header__menuItem"><a href="">Dashboard</a></li>
          {% elif request.user.is_authenticated and request.user.is_Recruiter %}
          <li class="header__menuItem "><a href="{% url 'RecruiterHome' %}">Home</a></li>
          <li class="header__menuItem"><a href="{% url 'Activites' %}">Activites</a></li>
          <li class="header__menuItem {% if request.user.is_authenticated and request.path == '/Recruiter/myjobs/' %}active{% endif %}"><a href="{% url 'myjobs' %}">My jobs</a></li>
         
          {% endif %}
          
          {% if request.user.is_authenticated %}
          <li class="header__menuItem {% if request.user.is_authenticated and request.path == '/accounts/account/' %}active{% endif %}"><a href="{% url 'account' %}">Account</a></li>


          <li class="header__menuItem {% if request.path == '/accounts/notofications/' %}active{% endif %} notification">
            <a href="{% url 'notofications' %}">Notifications</a>
            {% if has_new_notification %}
              <span class="notification-mark"></span>
            {% endif %}
          </li>
          
          <li class="header__menuItem {% if request.user.is_authenticated and request.path == '/accounts/logout/' %}active{% endif %}"><a href="{% url 'logout' %}" >Logout</a></li>
          {% else %}
          <li class="header__menuItem {% if request.path == '/accounts/login/' %}active{% endif %}"><a href="{% url 'login' %}" >Login/Sign Up</a></li>

          {% endif %}
        </ul>
      </nav>
      
     

      
    </div>
  </header>

Just as a reminder, you need to use the backtick - ` character to surround code or templates, not quotes or apostrophes. (I’ve taken the liberty of editing your post here to correct this.)

How are you rendering this as part of your pages? Is this a template that is part of your base template?

How are you passing has_new_notification into the context for the renderer? Do you have a context processor that is applying this globally, or are you adding it to the context in every page?

i am passing it from views.py. when there are new offers/application. the var is set to true

`def Notofications(request):

JobAppliesBeforeSort = None
JobOffersBeforeSort = None
JobApplies = None
JobOffers = None
SeekerObj = None
RecruiterObj = None
has_new_notification = False

if request.user.is_Seeker:
   JobOffersBeforeSort = Offers.objects.filter(seeker=request.user.seeker)
   JobOffers = sorted(JobOffersBeforeSort, key=attrgetter('is_new'), reverse=True)
   SeekerObj = request.user.seeker
   if any(offer.is_new for offer in JobOffers):
       has_new_notification = True
  

elif request.user.is_Recruiter:
    JobAppliesBeforeSort = Applications.objects.filter(jobpost__owner=request.user.recruiter)
    JobApplies = sorted(JobAppliesBeforeSort, key=attrgetter('is_new'), reverse=True)
    RecruiterObj = request.user.recruiter
    if any(application.is_new for application in JobApplies):
        has_new_notification = True




context = {'JobOffers': JobOffers , 'JobApplies':JobApplies , 'SeekerObj': SeekerObj , 'RecruiterObj': RecruiterObj , 'has_new_notification': has_new_notification}
return render(request, 'notofications.html', context)`

That’s fine for that page - which you say is working.

However, are you passing that variable through the context on every page? If not, that’s why you’re only seeing the mark on that page.

how can i include all the pages?

That’s the purpose of a context processor. You can create your own context processor that adds data to the context of every template being rendered. (Also see the section at Using RequestContext.)

i did the context processor in my main app but now when i run the app i encounter an error: dictionary update sequence element #0 has length 0; 2 is required
it was raised in accounts.views.main
this is my accounts.views.main
def main(request):
return render(request, ‘main.html’)

First, please remember to surround code between lines of three backtick - ` characters.

Also, when you’re asking for assistance with an error, post the complete traceback. (Also surrounded between lines of three backticks.)

If you’re having a problem with a context processor, you’ll need to post the code for it here.

context processor:

from Recruiter.models import Offers
from operator import attrgetter
from django.contrib.auth.decorators import login_required

@login_required(login_url='login')
def notifications_context(request):

    JobAppliesBeforeSort = []
    JobOffersBeforeSort = []
    SortJobApplies = []
    SortJobOffers = []
    has_new_notification = False

    if request.user.is_Seeker:
       JobOffersBeforeSort = Offers.objects.filter(seeker=request.user.seeker)
       SortJobOffers = sorted(JobOffersBeforeSort, key=attrgetter('is_new'), reverse=True)
       if any(offer.is_new for offer in SortJobOffers):
           has_new_notification = True
      

    elif request.user.is_Recruiter:
        JobAppliesBeforeSort = Applications.objects.filter(jobpost__owner=request.user.recruiter)
        SortJobApplies = sorted(JobAppliesBeforeSort, key=attrgetter('is_new'), reverse=True)
        if any(application.is_new for application in SortJobApplies):
            has_new_notification = True


    return {
        'SortJobOffers': SortJobOffers , 'SortJobApplies':SortJobApplies , 'has_new_notification': has_new_notification
    } ```
Traceback:
```Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 4.2.1
Python Version: 3.10.11
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'Seeker.apps.SeekerConfig',
 'Recruiter.apps.RecruiterConfig',
 'accounts']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Athee\Downloads\Hiral\accounts\views.py", line 436, in main
    return render(request, 'main.html')
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\template\base.py", line 173, in render
    with context.bind_template(self):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "C:\Users\Athee\Downloads\Hiral\eenv\lib\site-packages\django\template\context.py", line 254, in bind_template
    updates.update(processor(self.request))

Exception Type: ValueError at /
Exception Value: dictionary update sequence element #0 has length 0; 2 is required```

A context processor is not a view. You do not apply the login_required decorator on it.

if i removed it i get an error because it won’t recognize: is_Seeker and is_Recruiter

I don’t understand what you’re saying here. I don’t see any references to anything named is_Seeker or is_Recruiter in this context_processor.

I hope you’re not also trying to use this context_processor as a view - that would be wrong. A context_processor is something completely different than a view.