2

I have a database that uses a UTF-8 charset encoding. When I use the shell prompt to run mysql and select rows from tables, I can see the characters just fine (Frédéric Bélier). However, when running my django project and viewing a page in browser the field shows up as Frédéric Bélier. The HTML page as a charset meta tag of UTF-8.

When opening my views file (and template file) in Gedit I see that the charset is set to UTF-8 as well. However, when I run file -i views.py the output is views.py: text/x-java; charset=us-ascii / ASCII Java program text, with CRLF line terminators.

Any advices on what can be wrong and how it can be fixed?

5
  • Did you check your settings.DEFAULT_CHARSET? Commented Jan 28, 2012 at 20:45
  • does adding "# -- coding: utf-8 --" change anything? Commented Jan 28, 2012 at 21:23
  • Django+MySQL: How To Fix Unicode (aka Mysterious Question Marks) - Standard Deviations -> parand.com/say/index.php/2008/06/11/… Commented Jan 29, 2012 at 6:59
  • I don't think that the encoding of your *.py files has anything to with it. Commented Jan 29, 2012 at 11:35
  • settings.DEFAULT_CHARSET is set to utf-8 and I tried adding "# -- coding: utf-8 --", with not much success... @Efazati - I already have these settings configured correctly as shown in that post. Commented Jan 29, 2012 at 11:43

1 Answer 1

1

I am not a Django expert but perhaps it has something to do with a

  1. HTTP Header or Document Header

  2. A Django configuration. In Python a string is not necessarily unicode (unlike .NET for example)

My gut tells me that 2 in the probable situation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.