Skip to content Skip to sidebar Skip to footer

I Am Extending My Header And Footer But When I Pass Data In Footer It Is Visible Only At Home Page Not On Other Pages

I am extending my header and footer but when I pass data in footer it is visible only at home page not on other pages. I know that I have to pass that data on every pages but I am

Solution 1:

If you need your data in every pages, then you can use context processor.

In you app folder, create context_processor.py

In context_processor.py:

defcontext_processor(request):
    context = {}
    context['data'] = 'Some data'return context    

In settings.py:

TEMPLATES = [
    {
        ...,
        'OPTIONS': {
            ...,
            'app_name.context_processor.context_processor'
        }
    }
]

In your templates. In your case, you can use in your footer.html

{{data}}

FYI: You don't need to work with your views also.

Solution 2:

context_processor.py

from designzoned.models import ServicesModel
defcontext_processor(request):
   context = {}
   context['service_list'] = ServicesModel.objects.all()
   return context

settings.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'django.template.context_processors.request',
            # In below line you have to write like this'designzoned.context_processor.context_processor',
        ],
    },
},

]

header.html

<ulclass="dropdown-menu">
   {% for service in service_list %}
      <li><ahref="{% url 'services_detail' service.slug %}">{{ 
       service.name }}</a></li>
   {% endfor %}
</ul>

Post a Comment for "I Am Extending My Header And Footer But When I Pass Data In Footer It Is Visible Only At Home Page Not On Other Pages"