but the closest thing was SPACELESS
I tried to use it like this:
{% block data %}{% spaceless %}{{ story.tease }}{% endspaceless %}{%
endblock %}
But it didnt work.
First off - you're going to need to help us out a bit:
- What does a TRIM filter do? Perhaps it change the colour of the trim
on your website?
- Why doesn't SPACELESS 'work'? It works fine for me, and there are an
extensive set of tests that demonstrate all the ways it works. What
should it be doing that it isn't doing?
Secondly - Django 0.91 is extremely old; I _really_ wouldn't recommend
building new sites on this version if you can possibly avoid doing so.
If there _was_ a problem with SPACELESS in v0.91, it has almost
certainly been fixed in the two years since 0.91 was released; if it
hasn't been fixed, we won't be making a point release of 0.91 to
include the change.
Yours,
Russ Magee %-)
I suspect what some languages call Trim is the Python
function/method "strip()". Since this is a method of all string
objects, and Django calls callables, just using {{
story.tease.strip }} may do what the OP wanted.
> - Why doesn't SPACELESS 'work'? It works fine for me, and there are an
> extensive set of tests that demonstrate all the ways it works. What
> should it be doing that it isn't doing?
I suspect that the OP misunderstood "spaceless" to mean strip()
which of course doesn't work as strip() :)
> Secondly - Django 0.91 is extremely old; I _really_ wouldn't recommend
> building new sites on this version if you can possibly avoid doing so.
Seconded. .95 or .96 at a minimum :)
-tim
I'm stuck on 0.91 at work and I dont think they plan on upgrading
anytime soon (its beyond my control)
I'm not sure SPACELESS doesnt work, maybe because its around the
variable story.tease? I cant do anything via python either, I dont
have permission and I wouldnt know how anyway, all I deal with is
templates
Should TRIM delete *all* whitespace, or just leading/trailing
whitespace? Trim functions usually just remove leading/trailing
whitespace.
> {% block data %}{% spaceless %}{{ story.tease }}{% endspaceless %}
> {%endblock %}
You may be able to get away with simply using
{{ story.tease.strip }}
If you need to remove *all* whitespace, not just the
leading/trailing whitespace, you'll have to create your own
filter to do it. However, it's a fairly simple filter process:
import re
from django.template.defaultfilters import stringfilter
from django import template
register = template.Library()
whitespace_re = re.compile(r'\s')
@register.filter(name='remove_whitespace')
@stringfilter
def remove_whitespace(s):
return whitespace_re.sub('', s)
If the above "{{ story.tease.strip }}" doesn't work for some
reason (because "tease" is an object rather than a string, most
likely), you can create a filter out of it the same way, only using
@register.filter(name='strip')
@stringfilter
def strip(s):
return s.strip()
Either of these should then be usable as
{{ story.tease|strip }}
or
{{ story.tease|remove_whitespace }}
You can learn all about creating custom filters at
http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters
-tim
This behaviour has changed in the SVN version of Django. Now spaceless
will remove all spaces between tags. The documentation for the tag
explains a few other cases where spaces won't be removed.
> I'm not sure SPACELESS doesnt work, maybe because its around the
> variable story.tease? I cant do anything via python either, I dont
> have permission and I wouldnt know how anyway, all I deal with is
> templates
Unfortunately, I don't think there is much we can do to help, then. If
you can't update Django, and you can't write a custom template, you're
pretty much stuck with the tags 0.91 offers, and spaceless is pretty
much the only tag that does something like you describe.
Yours,
Russ Magee %-)