If you have a solution that is fine.

But if you did the business logic in the view, there is no need for

{%- if interests|length > 0 %}   and you would  simply return your
dictionary values while rendening as a variable that contains actual
values
and no need for the if statement which provides the extra carriage
return

{% for event, interests in report.items %}
           {{event}}

On Aug 14, 7:28 am, Sam Lai <samuel....@gmail.com> wrote:
> On 14 August 2011 14:00, Python_Junkie <software.buy.des...@gmail.com> wrote:
>
> > I think that if you performed the logic to determine if there actually
> > is something in the interest for that row in the view and
> > then only pass those components from the view, and not in the template
> > then your problem goes away.
>
> I don't think so, but I haven't tested it. Django's template parser
> does not remove newlines anywhere, even if only a template directive
> exists on that line. For HTML, this isn't an issue. You can try
> sacrificing template readability by putting everything on to one line.
>
> There has been a fair bit of discussion about this, but no consensus
> was arrived at. For now, the better solution is to use jinja2
> (http://jinja.pocoo.org/). Its language is based on Django's, and is
> largely compatible, but it has the added bonus of being able to remove
> newlines like so,
>
> {%- if interests|length > 0 %}
> ...
> {%- endif %}
>
> Notice the - after the % sign. This tells jinja2 to remove the
> previous newline character. You can also add them at the closing % to
> remove the following newline character.
>
> It is pretty easy to use with Django (and many people do), and you can
> just use it for this particular template, leaving all others to use
> Django's in-built templating system.
>
>
>
>
>
>
>
>
>
> > On Aug 13, 8:53 pm, CrabbyPete <pete.do...@gmail.com> wrote:
> >> I'm using the django template system for format a text email. I send
> >> it a dictionary and it formats the output. The problem is that it
> >> inserts lots of newlines
>
> >> Here is the template, and reports is a dictionary that contains an
> >> event and a dictionary of interests
>
> >> Weekly Contact List For {{date}}
> >> {% for event, interests in report.items %}
> >>     {% if interests|length > 0 %}
> >>         {{event}}
> >>         {% for interest, value in interests.items %}
> >>             {{ value }} {% if value == 1 %} lead {% else %} leads {%
> >> endif %} for {{ interest }}
> >>         {% endfor %}
> >>     {% endif %}
> >> {% endfor %}
>
> >> Is there a way for it just to print the lines without adding all the
> >> extra blank lines when interests = 0?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-users@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.

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

Reply via email to