extend base.html problem
Asked Answered
C

4

21

I'm getting the following error:

Template error

In template /home/mo/python/django/templates/yoga/index.html, error at line 1
Caught TemplateDoesNotExist while rendering: base.html
1 {% extends "base.html" %}
2 
3 {% block main %}
4     <p>{{ page.title }}</p>
5     <p>{{ page.info}}</p>
6     <a href="method/">Method</a>
7 {% endblock %}
8 

this is my base.html file, which is located at the same place as index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <div style="width:50%; marginleft:25%;">
    {% block main %}{% endblock %}
    </div>

what exactly is going on here? should the base.html file be located somewhere else?

Cookhouse answered 17/6, 2010 at 23:48 Comment(0)
S
22

"At the same place" as yoga/index.html means that the template is actually yoga/base.html.

Sil answered 17/6, 2010 at 23:54 Comment(0)
L
18

Assuming TEMPLATE_DIRS contains /home/mo/python/django/templates/, without the .../yoga/, so you need to:

move base.html into /home/mo/python/django/templates/

OR

write {% extends "yoga/base.html" %} in your template

Licht answered 18/6, 2010 at 5:27 Comment(1)
Of the two fix options, I think best practice would be to put base.html in /home/mo/python/django/templates/ and leave your extends reference to it unchanged. That will keep the app modular. Another site you build can chose to use your app's base.html or ovrerride it and force your app to take on the new header/footer/style of the new site. I think this is how Pinax does themes, etc.Fireproof
A
5

Is base.html in a directory in the TEMPLATE_DIRS list in your settings file?

Aperiodic answered 18/6, 2010 at 0:3 Comment(0)
T
1

Base.html file must be located at the base of templates folder to use ' base.html ' , if located in another folder such as: templates / home / base.html , then you must specify the path using

{ % Extends ' home / base.html '% }
Thurgau answered 5/6, 2015 at 5:46 Comment(1)
Does your answer add anything more to it than Ignacio Vazquez-Abrams's and Evgecyn's answers? I doubt it does.Solicitor

© 2022 - 2024 — McMap. All rights reserved.