-2

I have base template base.html and page.html and page2.html, who extend base.html

page.html

{% extends 'base.html' %}

page2.html

{% extends 'base.html' %}

I want to receive some context to base.html when i send request to page.html and page2.html

How can i do it? Real example, if it possible.

Now i write data to every view, but it is wrong way, i think.

wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • 1
    Possible duplicate of [Django: send context to 'base.html'](https://stackoverflow.com/questions/47894252/django-send-context-to-base-html) – Anas Abu Farraj Mar 14 '19 at 07:04

1 Answers1

0

The base template receives the same context data as the templates extending it. So you can do something like this in the base template without problem.

#base.html
<title>{{ title }}</title>
p14z
  • 1,760
  • 1
  • 11
  • 17
  • yes, but i must add this context to every view, which extend base template. I don't want do it – Vadim Beglov Mar 14 '19 at 05:40
  • Sounds like you need a context processor, refer to this question https://stackoverflow.com/questions/2893724/creating-my-own-context-processor-in-django – p14z Mar 14 '19 at 22:39