On Fri, 2010-01-22 at 15:07 -0500, Bill Freeman wrote:
> I believe that you will find that the file
> tags/find_which_display.html has a newline
> at it's end.  If you don't have the *nix utility od, you can, with any
> conventint
> python, do:
> 
> f=open('path_to_tags_template_dir/tags/find_which_display.html', 'rb')
> s=f.read()
> f.close()
> print repr(s)
> 
> Probably you have an editor that insists on ending files with
> newlines.  Or perhaps
> you had not considered that newline.  Anyway, I dummied up a test
> version of your
> code, and it works fine for me, with no trailing newline.
> 
> Bill

I use gedit, and tried it nano and vi also, but all of them add
automatically a newline \n at the end of the files.. 

I used sed to have a file without newline at the end. 

echo -en "{{display_url}}" | sed ':a;N;$!ba;$s/\(.*\)\n/\1/' ->
find_which_display.html

Yes funny but it works quite well. 

Thanks


> 
> On Fri, Jan 22, 2010 at 1:15 PM, Ali Rıza Keleş <ali.r.ke...@gmail.com> wrote:
> >
> > On Fri, 2010-01-22 at 12:55 -0500, Bill Freeman wrote:
> >> I'm pretty sure that your templatetag does produce the newline.  The url 
> >> tag,
> >> for example, doesn't add a newline.  How about posting the code?
> >>
> >
> > Code here:
> >
> > @register.inclusion_tag('tags/find_which_display.html')
> > def find_which_display(photo):
> >    if photo.source == "ext":
> >        display_url = photo.get_ext_url()
> >    else:
> >        display_url = photo.get_display_url()
> >    return {'display_url': display_url}
> >
> >
> > and tags/find_which_display.html:
> >
> > {{ display_url }}
> >
> > just have one line doesn't have the second.
> >
> >
> > i tried to return like below but it was same.
> >
> >    ...
> >    return {'display_url': remove_newlines(display_url)}
> >
> >
> > def remove_newlines(text):
> >    normalized_text = normalize_newlines(text)
> >    return mark_safe(normalized_text.replace('\n', ''))
> >
> >
> >
> > Thanks
> >
> > --
> > Ali
> >
> >
> >
> >
> >> On Fri, Jan 22, 2010 at 12:37 PM, Ali Rıza Keleş <ali.r.ke...@gmail.com> 
> >> wrote:
> >> > Hi,
> >> >
> >> > I have a templatetag which decides somthing and returns it. I works well
> >> > within HTML, but it causes error while it is in JavaScript, because of
> >> > newline which is produced by django rendering this templatetag.
> >> >
> >> > For example:
> >> > <img src="{% find_which_display photo %}" /> produces
> >> >
> >> > <img src="http://media.xxxx.com/images/2010/01/22/test_image.jpg
> >> > " />
> >> >
> >> > and yes it has newline but it works and display image.
> >> >
> >> > But here:
> >> > <script>
> >> > ...
> >> > replacePhoto('{% find_which_display photo %}');
> >> > ...
> >> > </script> produces
> >> >
> >> > <script>
> >> > ...
> >> > replacePhoto('http://media.xxxx.com/images/2010/01/22/test_image.jpg
> >> > ');
> >> > ...
> >> > </script>
> >> >
> >> > and of course it fails.
> >> >
> >> > I am sure that my templatetag find_which_display does not produce this
> >> > newline, i tried and tested it, also I dont know who does and how I can
> >> > fix it.
> >> >
> >> > Thanks for any help..
> >> >
> >> > --
> >> > Ali Rıza Keleş
> >> >
> >> > --
> >> > 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 at 
> >> > http://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-us...@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.
> >
> >
> 

-- 
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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to