Chartjs-Django 1.11 – child template not inheriting from parent

1πŸ‘

βœ…

Your view should be using charts.html, not chart_base.html (which it extends).

class HomeView(View):
    def get(self, request, *args, **kwargs):
        return render(request, 'chart.html')

You could use TemplateView instead of View:

class HomeView(TemplateView):
    template_name = 'chart.html'

In your charts.html the comment and <script> tag are not in any block. That means that they won’t be included in the rendered template, so you can remove them.

{% extends 'chart_base.html' %}

<!-- charts.html jquery -->
    <script>
    {% block jquery %}

1πŸ‘

In your base.html you have a typo. You are closing the <div> with a <container> tag.

<footer class="footer">
    <div class="container">
        {% block footer %}
        {% endblock %}
    </container>
</footer>

It should be:

<footer class="footer">
    <div class="container">
        {% block footer %}
        {% endblock %}
    </div>
</footer>

Also wrap charts.html in a block so it can be included anywhere.

Leave a comment