[GeoNode-users] Template extension over multiple apps

Simone Dalmasso simone.dalmasso at gmail.com
Tue Nov 14 09:08:47 PST 2017


Stefano did you add all the apps in the installed app directive?
Ps in an ideal design it should be avoided to inherit from other app’s
template in favor of a common one at project level.

Best

Il giorno mar 14 nov 2017 alle 17:35 <Stefano.LUONI at ext.ec.europa.eu> ha
scritto:

> Hi George,
>
> thank you for your answer. I was following a tutorial and I didn't notice
> that there was already an empty site_base template under Geonode
> directories (geonode/geonode/templates/site_base.html). This file is
> visible by all custom apps, hence it works as a starting point to customize
> the look of the pages, as you poited out.
> My question was different, though: I'd like to extend template across
> apps, so if we go back to the example directory tree, let's say that I want
> to extend app1_base.html from app2_base.html.
> As far as I know, enabling both APP_DIRS or specific loaders from
> setting.py should do the job; the problem is that if I try to do that, I
> cannot extend templates from GeoNode directory anymore because they're not
> found.
>
> LOCAL_ROOT = os.path.abspath(os.path.dirname(__file__))
> TEMPLATES = [
>     {
>         'BACKEND': 'django.template.backends.django.DjangoTemplates',
>         'DIRS': [os.path.join(LOCAL_ROOT, 'templates')],
>         'APP_DIRS': True,
>         'OPTIONS': {
>            'context_processors': [
>                "django.contrib.auth.context_processors.auth",
>            ],
>         }
>    },
> ]
>
> If I edit the DIRS in TEMPLATE settings, explicitly adding the GeoNode
> template path (../../geonode/geonode/templates), I start getting other
> errors, like the following:
>
> *KeyError* : from geonode/geonode/templates/_announcements.html ( {%
> announcements as site_wide_announcements %} )
>
> Can you help me understanding what I'm doing wrong?
>
> Best regards,
> Stefano
>
> ------------------------------
> *From:* gkpetrak [gkpetrak at gmail.com]
> *Sent:* 14 November 2017 15:49
> *To:* LUONI Stefano (JRC-ISPRA-EXT); geonode-users at lists.osgeo.org
> *Subject:* Re: [GeoNode-users] Template extension over multiple apps
>
> Hello Stefano,
>
>
> You don't have to name site_base.html or index.html the base templates of
> your apps. You should name them in a way like: app1_base.html. So your
> directory tree will look like this:
>
> -virtual_environment
> -geonode
>     -geonode
>         -templates
>             -base.html
>             -index.html
> -custom_project
>     -app1
>         -templates
>             -app1_base.html (extends site_base.html which extends
> base.html)
>             -app1_index.html (if It's required)(extends site_index.html
> which extends index.html)
>     -app2
>         -templates
>             -app2_base.html (extends site_base.html which extends
> base.html)
>             -app2_index.html  (if It's required) (extends site_index.html
> which extends index.html)
>
>
> As GeoNode is composed of many apps see for example the directory
> structure of "layers" app
>
>
> site_base.html and index_base.html is the  base template of your GeoNode
> project in order to customize your site.
>
>
> Best Regards,
>
> George
>
>
>
> On 14/11/2017 02:48 μμ, Stefano.LUONI at ext.ec.europa.eu wrote:
>
> Hi everyone,
>
> I know that it sounds more of a Django related question, but as a non
> Django expert I'm a bit confused about the ways to extend templates.
>
> *The problem*
> In a development environment, suppose we have created a new app and
> suppose we call it *app1*; we can customise the page look by editing *site_base.html
> *for global parts, *index.html *or other specific templates, knowing that
> site_base will extend *base.html *from geonode/templates folder, and so
> on.
> What if we create another custom app and we call it *app2*: how can we
> define templates that could inherit from what was already defined by
> *app1*?
>
> The directory tree looks like this:
>
> -virtual_environment
> -geonode
>     -geonode
>         -templates
>             -base.html
>             -index.html
> -custom_project
>     -app1
>         -templates
>             -site_base.html (extends base.html)
>             -site_index.html (extends index.html)
>     -app2
>         -templates
>             -new_template => how to extend site_base.html?
>
> The issue I'm facing is that as soon as I enable context_processors in my
> settings.py, I get an error because the Geonode base.html template is not
> found (from extends base.html in geonode/base/templates/geonode_base.html).
> I tried using different configurations with loaders like app_namespace or
> apptemplates with no luck.
>
> Do you have any suggestions for solving this?
>
> Thanks,
>
> Stefano
>
>
>
>
>
>
> _______________________________________________
> geonode-users mailing listgeonode-users at lists.osgeo.orghttps://lists.osgeo.org/mailman/listinfo/geonode-users
>
>
> _______________________________________________
> geonode-users mailing list
> geonode-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/geonode-users
>
-- 
Simone
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20171114/8cfe28c5/attachment.html>


More information about the geonode-users mailing list