[Fixed]-Django template extends not working

19πŸ‘

βœ…

Well everything is fine, the trouble that you are having is that
you are confused, just naming a block in base does not calls it.
Mark the difference between extends and include.
You have counfused extends to include.

Once in your views if you call say index.html it will be rendered properly.
The effect you want can be achieved by changing the base.html in your views to index.html.

Hope this helps. more can be read here: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

πŸ‘€whatf

3πŸ‘

For more people who end up here (as myself), main thing to note is that when you use {% extends 'something.html' %}, you cannot use anything other than these template tags at the top-level.

You can obviously have html tags inside these tags (like block tags), but don’t put ANYTHING outside the template tags.

πŸ‘€N K

0πŸ‘

Also helps if you change the path in extends, for example {% extends 'mysite/index.html' %}. And view function must render the file with extends, not the basic one.

πŸ‘€line9

0πŸ‘

In views.py, you have to call the template that extends the other template, not the other way around. In your example you should call nav.html.

πŸ‘€jparty

0πŸ‘

try do this

{% extends 'appname/index.html' %}
πŸ‘€AHMED dz

Leave a comment