Django-Child template-Base.html not rendering - html

I am using the Django template system in my app, and in the child template I reference the {% extends "base.html" %} accordingly, though when redenring the template, it only comes up with the html tags and no css styling-thus not picking up the base.html template altogether.
Please advise on what I am doing wrong?. Could it be an issue with it not finding the location of my base.html template?
This is the child template code:
{% extends "base.html" %}
{% block content %}
{% for field in form %}
{{ form }}
{% endfor %}
{% endblock %}
This is the base.html template code (relevant parts):
<div id="content">
<h2>
Page heading - This is where the functionality goes...
</h2>
<FIELDSET><INPUT class=Test value="Test" type=submit></FIELDSET>
{% block primary %}{% endblock %}
</div>
Please let me know if you need any firther information to solve this issue.
-I will add the views.py this evening (London time)--
This all all sorted, many thanks for the help
Thanks

Like goliney mentioned...
You need to have a part in your base.html file that has
{% block content %}
{% endblock %}
Then you can override that in your other template that extends the base.html template.
Currently in your child template you could do a
{% block primary %}
whatever you want here and this would show up where you marked on the base.html template
{% endblock %}
Also not sure if you are just putting together a quick example or not. You will need to create the
<form action="" method="post">{% csrf_token %}
for loop here
</form>

Related

I can't copy content from an html tag into another django template

Good night friends.
I'm trying to display the content of a tag in a template, in another template, using the django "extends" method. Works perfectly with when it comes to "normal", "typed" content:
this works:
{% block part_of_site %}
<div id='tag2'>Context</div>
{% endblock %}
using a variable, you can't copy to another template:
{% block part_of_site %}
<div id='tag2'>{{ variable }}</div>
{% endblock %}

Unable to extend django template properly?

I have a base.html template which contains basic html definitions .The other templates are defined below
// pages/dashboard.html
{% extends 'base.html' %}
{% block body %}
{% include 'components/nav.html' %}
{% include 'components/dashboard.html' %}
{% endblock %}
// components/dashboard.html
<div class="page-container">
<div class="main-page">
{% block dashboard %}
{% endblock %}
</div>
</div>
// mailer/new.html
{% extends 'pages/dashboard.html' %}
{% block dashboard %}
<h1>hello</h1>
{% endblock %}
The view renders mailer/new.html the problem is that the block containing <h1>hello</h1> is not working. Where am i going wrong with that ?
{% include %} doesn't work that way. See the note in the documentation for that tag:
Blocks are evaluated before they are included. This means that a template that includes blocks from another will contain blocks that have already been evaluated and rendered - not blocks that can be overridden by, for example, an extending template.

Django extends template issue

Okay so I have my index.html file which has a file called info.html which exntends from the index.html file but it isn't quite working currently. Here's my code:
index.html
<body>
{% include "home/quote.html" %}
{% include "home/intro.html" %}
{% block content %}
{% endblock %}
{% include "home/projects.html" %}
{% include "home/goals.html" %}
</body>
info.html
{% extends "home/index.html" %}
{% block content %}
<section class="info-section">
<div class="info-section_content">
{% include "home/includes/info-content.html" %}
</div>
</section>
{% endblock %}
Essy Fix!
In views.py in the apps directory i was rendering the parent file (index.html) so I have now switch to render the child file (info.html) and it now works.
I would need some more information on your project to know for sure, but I would check to make sure that you are referencing the proper namespace here:
{% extends "home/index.html" %}
For instance if the path is something like templates/home/something/info.html or templates/something/home/info.html this could be the issue.

djangocms template inheritance

Django-cms multiple inheritance does not work.
I have the following template structure:
base.html
{% block content %}
{% endblock content %}
page1.html
{% extends "base.html" %}
{% block test %}
{% endblock test %}
page2.html
{% extends "page1.html" %}
{% block content %}
<div>foo</div>
{% endblock content %}
{% block test %}
<div>foo</div>
{% endblock test %}
The problem is that the block test in page2 HTML is not rendered. Only the blocks from base.html are rendered. If I include block test in base.html is also gets rendered in page2
Does your base.html contain {% block test %}?
Your base template must contain the block you want to override. You can add additional blocks in child templates, but they must be contained within a base block.
See https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
base.html is your top level template. This would normally be the thing that starts with an html doctype and ends with a </html> tag. Everything else has to have a place to go in there. All you have is a content block.
So where would the test block go? You've tried to put it in page1.html, but it still needs a place to go in the parent template.

django template inheritance use same tag multiple templates

I am using the django template system fine-though is there a way to use the same variable inheritance tag for more than one template without pulling in the data from the other template too.
<div id="content-container3">
{% block content-container2 %}{% endblock %}
</div>
So I want to use the above in say people.html template and test.html template.
for example:
{% extends "base.html "}
{% block content-container2 %}{% endblock %}
Though it cross refernces information from two templates in this case -does each variable inheriatnce tag have to be unique?
try to move this part of code to different file (content_container3.html) and use include tag... or I did not understand your question :)
I think you should try nesting blocks like the below example.
{% block first_section %}
{% block first_section_upper %}
{{block.super}}
{% endblock first_section_upper %}
<h1 class="display-5">Some content</h1>
<h5 style="color: white !important;" class="display-5"> *Your text here*</h5>
<p class="lead">The Algorithms that run our Universe</p>
{% block first_section_lower %}
{{block.super}}
{% endblock first_section_lower %}
{% endblock first_section %}
The h1 tag and p tags can be different for every new template. As far as i could understand, this might solve your problem.