Encoding ISO-8859-1

195 views
Skip to first unread message

ulferik

unread,
Nov 16, 2009, 3:59:46 AM11/16/09
to Django users
My problem is that when I put one of these characters (´ Å Ä Ö) in the
template I get an error like this "UnicodeDecodeError: 'utf8' codec
can't decode bytes in position 578-579: invalid data"
Normally I specify the encoding in meta like this "charset=ISO-8859-1"
or "xml version="1.0" encoding="ISO-8859-1" ". There must be a way of
changing the encoding in Django. If anyone know how to do that please
post it here:
Ulferik

Karen Tracey

unread,
Nov 16, 2009, 8:11:45 AM11/16/09
to django...@googlegroups.com

ulferik

unread,
Nov 16, 2009, 10:08:50 AM11/16/09
to Django users
Thank's Karen for your reply.
With php+smarty I do the same I make a base template on which I have
some
stuff that is the same for all. In the template I place a meta tag
with charset=ISO-8859-1
and everything is fine. With Django it doesn't make any difference
what I place in meta or
xml tags. The template is processed and it is UTF-8 whether I like it
or not.
This not a matter of database or views or models it is a base
template.
I have read the manual regarding charset and I can't make any sence
from it. What I need
is an example that shows how to...
Ulferik

On 16 Nov, 14:11, Karen Tracey <kmtra...@gmail.com> wrote:

Karen Tracey

unread,
Nov 16, 2009, 10:20:22 AM11/16/09
to django...@googlegroups.com

On Mon, Nov 16, 2009 at 10:08 AM, ulferik <ulf...@yahoo.com> wrote:
Thank's Karen for your reply.
With php+smarty I do the same I make a base template on which I have
some
stuff that is the same for all. In the template I place a meta tag
with charset=ISO-8859-1
and everything is fine.

The meta tag, I'd guess, will affect how the browser interprets the data.
 
With Django it doesn't make any difference
what I place in meta or
xml tags. The template is processed and it is UTF-8 whether I like it
or not.
This not a matter of database or views or models it is a base
template.
I have read the manual regarding charset and I can't make any sence
from it. What I need
is an example that shows how to...


FILE_CHARSET is a setting, so you need to put it in your settings.py file, not in any template file. Include:

FILE_CHARSET = 'iso-8859-1'

in your settings.py file (and, if necessary, restart your server).  Then Django will stop assuming that your template files are encoded in utf-8 and instead will read them assuming iso-8859-1 encoding.

Note if you also want to retrain this encoding, instead of utf-8, for all responses sent by your application, you will need to also set DEFAULT_CHARSET:

http://docs.djangoproject.com/en/dev/ref/settings/#default-charset

By default Django will encode outgoing responses in utf-8, so if you want to send your responses with another encoding you need to change this one also.  But I am not sure why you would want to do that instead of just sending the response using utf-8? 

Karen


ulferik

unread,
Nov 16, 2009, 10:36:17 AM11/16/09
to Django users
Karen I did as you said and it is amazing what know-how can do.
I am yours forever.
Ulferik

On 16 Nov, 16:20, Karen Tracey <kmtra...@gmail.com> wrote:

Hugo González Monteverde

unread,
Nov 16, 2009, 12:44:15 PM11/16/09
to Django users
What editor are you using for the template? There's no point in
specifying the encoding as a meta if the actual html template files
has not been saved in that encoding. Use the same encoding in your
editor settings as you are using in your meta specification.

Either your template file has a BOM or Django is interpreting that it
should be UTF8. The easiest way to fix this is saving the file as UTF8
and changing your meta settings. All characters in Latin 1 are in
Unicode so you can stick to unicode for all of it.

ulferik

unread,
Nov 16, 2009, 2:07:42 PM11/16/09
to Django users
Hi Hugo.
I am using eclipse with pydev and have no idea how it is saved...
maybee you know that?
Ulferik
Reply all
Reply to author
Forward
0 new messages