Home > OS >  Django include template no data
Django include template no data

Time:01-21

I am trying to include a file, into my base.html Inside the base, inn the base.html

{% block content %}

{% include "something.html" %}
{% endblock %}

But nothing shows up from the included file, and I have tried to have blocks inn the something.html

{% block content %}
something something inside the something.html
{% endblock %}

I have also tried without using blocks, but nothing.

CodePudding user response:

What you want to do is

base.html

{% block content %}

{% include "something.html" %}

{% endblock %}

something.html

<div>my content in something</div>

If you you put a block statement in the included template it will not show up.

More details https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#include

CodePudding user response:

whatyouwanttoinclude.html

<body>
............
    {% block content %}
    {% endblock content %}
...........
</body>

whereyouwanttoinclude.html

{% extends 'whatyouwanttoinclude.html' %}
{% block content %}
    some html here
{% endblock content %}

Now when you render the template whereyouwanttoinclude.html, it will also show the contents of whatyouwanttoinclude.html

  •  Tags:  
  • Related