On Fri, Jun 24, 2011 at 5:21 PM, ydjango <neerash...@gmail.com> wrote:

> Just checking if anyone has any pointers?
> We are using Django 1.1.4
>
> On Jun 15, 2:03 pm, ydjango <neerash...@gmail.com> wrote:
> > I have rich text (in utf8) which I want to show in standard browser
> > tooltip.
> >
> > I strip html tags using strip_tags as they show as html tags in
> > tooltip.
> >
> > Issue is that it seems strip_tags is stripping or converting certain
> > turkish characters like ü   into weird special chars?
> >
> > I am unable to use django template's safe tag as data goes from django
> > view to xml to javascript.
> >
> > We are using UTF8 encoding in DB.
> >
> > Any ideas on how to solve?
>
>
It's very hard to say what might be going on here -- the strip_tags filter
is very simple, and is mostly just a regular expression applied to your
input. A large number of other people, I am sure, are using the tag without
noticing any such problem.

The one spot in the code that I can see that might cause problems is
django.utils.encoding.force_unicode -- it's possible that you are passing
something unexpected to that, and it is performing a conversion which
produces the characters you are seeing.

If you want to troubleshoot this, I would suggest the following:

1. Can you confirm that the data is really in the database in UTF8?

2. What do you get when you query the database from Django? At a minimum, I
would run a Django shell, import the models, and get a problematic instance
out of the database for printing. If you print the fields ("print
repr(my_instance.field_name)"), you should be able to see a proper unicode
object, something like u"This is the text with the ü")

    >>> from my_app.models import MyModel
    >>> my_instance = MyModel.objects.get(id=1234)
    >>> print repr(my_instance.field_name)

3. What happens when you pass that string to force_unicode?

    >>> from django.utils.encoding import force_unicode
    >>> print repr(force_unicode(my_instance.field_name))

4. What are you actually getting as HTML output? Django should be outputting
unicode, so you will have to ensure that your web server is providing an
appropriate Content-Type header, or that you have a <meta> tag in the html
header that specifies unicode. If those aren't there, then your browser will
have to guess the document encoding, and might be guessing wrong.

Hopefully that should get you enough visibility on the problem to see what
is happening. If none of that provides any clarity, then try posting those
answers here, and someone might be able to tell what's going on.

-- 
Regards,
Ian Clelland
<clell...@gmail.com>

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