Ivic
Ivic

Reputation: 69

Django admin not accepting latin-based alphabet

I am having problem when writing Croatian alphabet letters in django admin.

This is the error I get:

'ascii' codec can't encode characters in position 13-14: ordinal not in range(128)

I've made changes in my settings:

settings.py

LANGUAGE_CODE = 'hr-HR'
LANGUAGES = (
    ('hr', 'Hrvatski'),
)
DEFAULT_CHARSET = 'UTF-8'

This translates django-admin to Croatian, but Django still doesn't except Croatian letters.

I added this on top of models.py, views.py and admin.py

# -*- coding: utf-8 -*-

I changed __str__ to __unicode__ in models

models.py

class Book(models.Model):
    title = models.CharField(max_length=200)
    description = models.CharField(max_length=300)

    def __unicode__(self):
        return u'%s %s' % (self.title, self.description)

After changing my models.py letters like č,ć,đ become ?,?,?

This is what I put in master.html for my templates:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

What am I missing? Can somebody give me a hint?

Thanks for your time.

Upvotes: 1

Views: 333

Answers (1)

Alasdair
Alasdair

Reputation: 308849

Make sure your database is using UTF-8. You can specify UTF-8 when creating a MySQL database:

CREATE DATABASE <dbname> CHARACTER SET utf8;

See the docs for more info.

Upvotes: 1

Related Questions