Defining base templates for reusable apps

23 views
Skip to first unread message

Some Developer

unread,
May 8, 2015, 9:00:29 PM5/8/15
to django-users
I'm looking into building a set of open source reusable apps for Django
and was wondering what the currently accepted best practice was for
defining base templates for reusable apps was?

I want my reusable apps templates to be easy to slot into an already
existing site design but I'm unsure of the best way of achieving that.
Should I define a base template in the app itself that basically works
on the whole of the app? If I did that what would be the best way of
letting other people modify that base template?

I really just want my app to fit into other users projects with the
minimum amount of fuss.

I guess I could specify the views myself and let the user create the
templates themselves. Would that be a decent option? That would allow
the user to design the templates in the best possible way.

Having said that I would also like to provide some default templates
that people could use if they didn't want to bother designing the
templates themselves. How could I allow them to override the default
template supplied by the view?

Any hints would be greatly appreciated :).

Bruno A.

unread,
May 9, 2015, 10:47:48 AM5/9/15
to django...@googlegroups.com
Hi,

I've never done it, but I myself want to do a similar thing, so I've been thinking about it a bit. The solutions I've thought of are the following:
  • Template inheritance, as you mention. You provide the base template, but it might not be straightforward for the app's user to override. The Django's admin is a good example of this, and it can be customized partially or entirely by adding an admin directory in your site's templates directory, there are also some apps providing new interfaces entirely.
  • Use the include tag to let your app's user define the main site canvas and just generate some basic HTML in the middle of their page, with their navbar, footer...
  • Along the same lines, provide in your apps custom template tags for the CSS, the JS you need and the content of your pages.
Now, I guess it depends on the complexity of the content your app provide, whether you need parameters, etc... 

Some Developer

unread,
May 11, 2015, 11:46:42 PM5/11/15
to django...@googlegroups.com
On 09/05/15 11:47, Bruno A. wrote:
> Hi,
>
> I've never done it, but I myself want to do a similar thing, so I've
> been thinking about it a bit. The solutions I've thought of are the
> following:
>
> * Template inheritance, as you mention. You provide the base template,
> but it might not be straightforward for the app's user to override.
> The Django's admin is a good example of this, and it can be
> customized partially or entirely by adding an admin directory in
> your site's templates directory, there are also some apps providing
> new interfaces
> <https://www.djangopackages.com/grids/g/admin-interface/> entirely.
> * Use the include tag
> <https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#include>
> to let your app's user define the main site canvas and just generate
> some basic HTML in the middle of their page, with their navbar,
> footer...
> * Along the same lines, provide in your apps custom template tags for
> the CSS, the JS you need and the content of your pages.
>
> Now, I guess it depends on the complexity of the content your app
> provide, whether you need parameters, etc...
>

Yeah I'll have to think about this some more. In all my previous
projects I have just used straight up template inheritance but in those
projects I haven't had to worry about a user needing to customise the
look and feel of the site.

By providing a base template it makes the project easier to develop but
I also think it makes it harder to customise by other users of the
project as they have to plugin in their own base template and create the
required blocks for the other templates to inherit from.

Reply all
Reply to author
Forward
0 new messages