Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » templating best practices in django [RSS Feed]

#1 Jan. 8, 2011 20:21:42

Mo M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templating best practices in django


Hi,

I'm wondering what would be the best practice for templating in django. I
plan on having a single theme in which heads and footers will almost be the
same across my project,

1. Should I great an app only for this purpose, in the sense, an app will
host a header and footer functions (methods) along with their views. Is that
the best practice?

2. my second question, if I am going to host a header somewhere centered. Is
it possible that I include or exclude certain css or js from the main
header?

3. Is there a django module that help organizing my js and css in a way?


4. last, what is django_compressor used for, I don't get the idea, If am
going to specify the paths to my js. Why does it combine them all in a
single file? does that make the loading faster?

thanks,

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 9, 2011 13:21:48

Mark (.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templating best practices in django


> 1. Should I great an app only for this purpose, in the sense, an app will
> host a header and footer functions (methods) along with their views. Is that
> the best practice?

You can use {% include "snippet.html" %} or a {% block name %}Default
template in your base template that you extend{% endblock %}. The
include will take a variable you can pass for the name of the snippet
and the block can easily be replaced by a block in your non base
templates. No app needed just use the templating system, it's
actually desinged to handle these types of things. You can also
generate different bases to extend if you want but find using blocks
and includes on one or two bases easier. The bases I use are for
skins and popups. Use the admin site templates to get a understanding
of {% extends base %} where base can be a template or variable naming
a template.

> 2. my second question, if I am going to host a header somewhere centered. Is
> it possible that I include or exclude certain css or js from the main
> header?

Again look at the block tags I have {% block css %} and {% block js %}
in my base templates and any default js/css. Start by looking at the
base.html in the admin application to start understanding how to set
templates up based on what I consider best practices.

> 3. Is there a django module that help organizing my js and css in a way?

There are a few I don't use them but google will know.

> 4. last, what is django_compressor used for, I don't get the idea, If am
> going to specify the paths to my js. Why does it combine them all in a
> single file? does that make the loading faster?

I believe it combines js/css into a cache that is then made available
to the client to keep the number of requests down which is a issue on
some sites. I suggest using YSlow to evaluate your site and a few
others to get an idea about performance and performance issues and see
if this may be something you need. Most browsers only allow 7 threads
at a time to a site so if your site requires 60 connections to
generate a page you start blocking based on performance etc this is an
issues with some sites.

Mark

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 9, 2011 20:41:44

Carles B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

templating best practices in django


In terms of best practices for Django templates, I recommend that you
try to use template inheritance extensively, in similar ways as when
you would use subclassing:

- Create a base.html template with everything that appears in all your
pages (common header and footer, generic html headers...).
- Create extension "hooks" in the form of {% block %} in any place you
would like to override in specific pages
- Extend that template for any page in your application
- Don't be afraid to create multiple levels of inheritance, e.g. sub-
templates of base for different sections of your site that require a
different layout.
- In many places where you could use {% if %} to create variants for a
page, you can do it more cleanly with inheritance

Besides the typical {% extends "base.html" %} (fixed template name), a
powerful option is {% extends variable_name %} where you can pass as a
context to your template the name of the "super-template" you want to
use.




On 8 Gen, 21:21, Mo Mughrabi <mo.mughr...@gmail.com> wrote:
> I'm wondering what would be the best practice for templating in django.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support