[Fixed]-Django and extending templates not working?

1👍

Nermic Kekic’s answer didn’t work for me.

I am not a expert but below is what worked for me.

The problem was my base.html(parent) didn’t know where to append the post.html(child) so I had to mention

{% block content %}
{% endblock %}

these two lines in body of my base.html also then it worked for me, as this block will tell the post.hml where to show the content of child.

0👍

I found the solution. The issue was not with the two html files, but it was in my views.py file. Basically in my index function in views.py was rendering base.html and therefore nothing was showing up on screen from post.html

Given that the post.html is extending base.html i needed to edit my index function to return and render post.html like bellow and this fix the code.

Hope this helps anyone else that is having similar issue.

This is the way my index function looks now in views.py

    from django.shortcuts import render
from django.http import HttpResponse


def index(request):
    return render(request, 'post/post.html', {'': ''})

0👍

{% block content %}
{% endblock content %}

You need to add above lines of code in your base.html file. And in your (post.html) file, you need to add these lines and the unique content inside these. This way Django knows where you can make changes to your post.html file.

Leave a comment