Theming: not able to override index.html

398 views
Skip to first unread message

alekto.a...@gmail.com

unread,
Dec 21, 2013, 2:06:34 PM12/21/13
to mezzani...@googlegroups.com
Hi,

I am trying to make my first theme, but I am not able to override the default index.html. 
This is my theme directory:
.
├── __init__.py
├── static
│   ├── css
│   ├── img
│   └── js
└── templates
    ├── base.html
    ├── includes
    │   └── footer_scripts.html
    └── index.html

And I have tried to add the theme as an app like this:
INSTALLED_APPS = (
    "theme",
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.redirects",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.sitemaps",
    "django.contrib.staticfiles",
    "mezzanine.boot",
    "mezzanine.conf",
    "mezzanine.core",
    "mezzanine.generic",
    "mezzanine.blog",
    "mezzanine.forms",
    "mezzanine.pages",
    "mezzanine.galleries",
    "mezzanine.twitter",
    #"mezzanine.accounts",
    #"mezzanine.mobile",
)

And this:

INSTALLED_APPS = (
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.redirects",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.sitemaps",
    "django.contrib.staticfiles",
    "mezzanine.boot",
    "mezzanine.conf",
    "mezzanine.core",
    "mezzanine.generic",
    "mezzanine.blog",
    "mezzanine.forms",
    "mezzanine.pages",
    "mezzanine.galleries",
    "mezzanine.twitter",
    #"mezzanine.accounts",
    #"mezzanine.mobile",
    "theme",
)

My index.html looks like this:
{% extends "base.html" %}
{% load i18n %}

{% block meta_title %}{% trans "Home" %}{% endblock %}
{% block title %}{% trans "Home" %}{% endblock %}

{% block breadcrumb_menu %}
<li class="active">{% trans "Home" %}</li>
{% endblock %}

{% block main %}
{% blocktrans %}
<h2>Congratulations!</h2>
<p>
    Test 1.. 2.. 3..
    Welcome to your new Mezzanine powered website.
    Here are some quick links to get you started:
</p>
<ul>
    <li><a href="/admin/">Log in to the admin interface</a></li>
    <li><a href="http://mezzanine.jupo.org/docs/content-architecture.html">Creating custom page types</a></li>
    <li><a href="http://mezzanine.jupo.org/docs/frequently-asked-questions.html#templates">Modifying HTML templates</a></li>
    <li><a href="http://mezzanine.jupo.org/docs/frequently-asked-questions.html">Other frequently asked questions</a></li>
    <li><a href="http://mezzanine.jupo.org/docs/configuration.html#default-settings">Full list of settings</a></li>
    <li><a href="http://mezzanine.jupo.org/docs/deployment.html">Deploying to a production server</a></li>
</ul>
{% endblocktrans %}
{% endblock %}

If someone can spot my (noobish)mistake, please let me know!
Thank you!

Luc Milland

unread,
Dec 21, 2013, 5:32:26 PM12/21/13
to mezzani...@googlegroups.com
Hi,
I think your mistake is here :

> This is my theme directory:
> .
> ├── __init__.py
> ├── static
> │ ├── css
> │ ├── img
> │ └── js
> └── templates
> ├── base.html
> ├── includes
> │ └── footer_scripts.html
> └── index.html

index.html should sit in templates/pages, not at "templates" root.
Let us know if it solves your problem !

regards,
Luc

Luc Milland

unread,
Dec 21, 2013, 5:38:38 PM12/21/13
to mezzani...@googlegroups.com
Oops, I answered too quickly, sorry. I have it in "pages" on my sites
using an editable index page, but it's not the default.

Did you install django-debug-toolbar ? It's handy to debug templates
paths.

regards,
Luc

alekto.a...@gmail.com

unread,
Dec 21, 2013, 6:28:37 PM12/21/13
to mezzani...@googlegroups.com
 
I actually manage to make my new theme working, I had to change the TEMPLATE_DIRS to:
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "theme/templates"),)

Does this mean that I have to change this variable if I would like to change to another theme, or should I place to theme-apps inside the templates/ directory?
I am confused, what is best practice here?

I have installed the django-debug-toolbar, it seems like it can be useful. Thank you for the tip :)
 



Stephen McDonald

unread,
Dec 21, 2013, 6:32:21 PM12/21/13
to mezzani...@googlegroups.com
The app should be a proper Python package which in the least means it should contain an empty __init__.py file. At some stage Django required each app have at least an empty models.py module also, I'm not sure if that's still true.

I'd guess that your app isn't being picked up due to this, so its templates directory isn't used.


--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Stephen McDonald
http://jupo.org

alekto.a...@gmail.com

unread,
Dec 23, 2013, 3:12:57 AM12/23/13
to mezzani...@googlegroups.com, st...@jupo.org
As you can see I have included a __init__.py file in my theme root directory. Have also tried including an empty models.py, but I am still not able to have my theme function without changing the TEMPLATE_DIRS in settings.py.

Anyway, thanks for your effort. I will update this post if I manage to get this to function. 

Stephen McDonald

unread,
Dec 23, 2013, 3:26:13 AM12/23/13
to mezzani...@googlegroups.com
Also ensure your theme app (a Python package) is importable, eg:

python manage.py shell
>>> import theme


On Mon, Dec 23, 2013 at 7:12 PM, <alekto.a...@gmail.com> wrote:
As you can see I have included a __init__.py file in my theme root directory. Have also tried including an empty models.py, but I am still not able to have my theme function without changing the TEMPLATE_DIRS in settings.py.

Anyway, thanks for your effort. I will update this post if I manage to get this to function. 

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tom Lockhart

unread,
Dec 23, 2013, 8:51:33 AM12/23/13
to mezzani...@googlegroups.com

On 2013-12-21, at 3:32 PM, Stephen McDonald <st...@jupo.org> wrote:

> The app should be a proper Python package which in the least means it should contain an empty __init__.py file. At some stage Django required each app have at least an empty models.py module also, I'm not sure if that's still true.

No, models.py is not required in an app for 1.5 (and pretty sure 1.4 also).

- Tom

Josh Cartmell

unread,
Dec 23, 2013, 1:55:47 PM12/23/13
to mezzani...@googlegroups.com
Hey Alekto, I'm not sure what is going on in your project, but you shouldn't have to change the TEMPLATE_DIRS setting.  I usually put themes just before mezzanine.boot (they definitely need to be before mezzanine.core.)   Are you using a default mezzanine-project created settings file?  If so have you modified anything?  Particularly, what does your TEMPLATE_LOADERS setting look like?

Does your project (not theme) have a templates folder?  If it does, and it contains an index.html it will override your theme's index.html (by default).  For example, in the following screenshot (of a project called rail), if the highlighted folder templates (the project's templates folder) had an index.html (it doesn't) it would override anything specified in the templates folder of the app theme.
Inline image 1


Screen Shot 2013-12-23 at 10.54.00 AM.png

Mehmet Özgür Bayhan

unread,
Dec 23, 2013, 7:20:45 PM12/23/13
to mezzani...@googlegroups.com
May U zip and share your project files with us? Because the problem may depends on so many things. I think U are missing something.

Patrick Sheridan

unread,
Jan 10, 2014, 2:52:47 PM1/10/14
to mezzani...@googlegroups.com
I'm not sure if you this is your problem (I'm very new to Mezzanine), but I ran into the same problem and it was a result of having a templates folder within the project directory in addition to the one you should have in your app directory, ie:

project
|--templates (1)
|--theme
      |--templates (2)

Once I deleted the first (1) templates directory, mezzanine began overriding.

If anyone has an explanation for this behavior, I'd like to learn more.

Ross Laird

unread,
Jan 11, 2014, 6:51:39 PM1/11/14
to mezzani...@googlegroups.com
Take a look here for a broad discussion, with many suggestions, for dealing with themes and templates.
As various people have pointed out, this type of issue can be caused by many things, and it might be useful to step through the process from the beginning.
Reply all
Reply to author
Forward
0 new messages