Saturday, May 9, 2015

Re: Defining base templates for reusable apps

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... 

On Friday, 8 May 2015 22:00:29 UTC+1, Some Developer wrote:
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 :).

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/90cbc6eb-304a-4396-9155-597a9f75879e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment