views:

72

answers:

3

I have both, django and mysql set to work with UTF-8. My base.html set utf-8 in head.

row on my db :


+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+
| id | psn_id | name                                                             | publisher                   | developer                   | release_date        |
+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+
|  1 | 10945- | まいにちいっしょ | Sony Computer Entertainment | Sony Computer Entertainment | 2006-11-11 00:00:00 |
+----+--------+------------------------------------------------------------------+-----------------------------+-----------------------------+---------------------+

the source code generated looks like :

まいにちいっしょ

and this is wat is displayed :/

why they are not showing the chars the way in this database?

+3  A: 

That source code, when placed into an otherwise empty HTML document, looks like this for me in Google Chrome, IE and Firefox:

まいにちいっしょ

Which appears to be what you want.

My only thought is that that is not really the source code, and you've in fact got source code that looks like this:

まいにちいっしょ

in which case you're HTML-encoding something that's already HTML-encoded.

If that's not the case, then I've no idea.

The source I used to test this is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; 
<html xmlns="http://www.w3.org/1999/xhtml"&gt; 
  <head> 
    <title>Foo</title> 
  </head> 
  <body> 
   <p>&#12414;&#12356;&#12395;&#12385;&#12356;&#12387;&#12375;&#12423;</p>
  </body> 
</html>
Dominic Rodger
A: 

As Dominic has said, the generated HTML source code is correct (these are your Japanese characters translated into HTML entities), but we're not sure, if you see the same code rendered in the page (in this case, you have probably set content-type to "text/plain" instead of "text/html" - do you use render_to_response() or HttpResponse() in the corresponding view.py method?), or your Japanese is rendered correctly but you just don't like the entities in the source code.

Since we don't know your Django settings and how do you render and return the page, it's difficult to provide you the solution.

mykhal
A: 

the problem is the auto escape django function ... my source code is like the one that Dominic pasted :

&#12414;&#12356;&#12395;&#12385;&#12356;&#12387;&#12375;&#12423;

i simple put the tag in places there i known that may be some diff chars:

{% autoescape off %}
xxxxx
{% endautoescape %}

and everything works like a charm... :D

than you all

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape

fabriciols
Actually, use the `safe` template filter, e.g. `{{ var|safe }}`. (Documentation on the page linked to by this answer.)
Michał Marczyk
"safe" is the better way ?
fabriciols
Well, not always, in fact sometimes `{% autoescape off %}` / `{% endautoescape %}` is really the only way to go, but with just one problematic variable's contents being unnecessarily escaped, I'd say it's best to be explicit about the intent to turn autoescaping off for that particular variable so as to decrease the probability of catching something which actually *should* be escaped in the `autoescape off` block. Obviously that would very likely be a bigger problem than overzealously escaping something where it's not desired could ever be.
Michał Marczyk