Django db encoding

Posted by realshadow on Stack Overflow See other posts from Stack Overflow or by realshadow
Published on 2010-05-03T09:25:47Z Indexed on 2010/05/03 10:38 UTC
Read the original article Hit count: 324

Filed under:
|
|

Hey,

I have a little problem with encoding. The data in db is ok, when I select the data in php its ok. Problem comes when I get the data and try to print it in the template, I get - Å port instead of Šport, etc.

Everything is set to utf-8 - in settings.py, meta tags in template, db table and I even have unicode method specified for the model, but nothing seems to work. I am getting pretty hopeless here...

Here is some code:

class Category_info(models.Model):
  objtree_label_id = models.AutoField(primary_key = True)
  node_id = models.IntegerField(unique = True)
  language_id = models.IntegerField()
  label = models.CharField(max_length = 255)
  type_id = models.IntegerField()

class Meta:
    db_table = 'objtree_labels'

def __unicode__(self):
    return self.label

I have even tried with return u"%s" % self.label.

Here is the view:

def categories_list(request):
  categories_list = Category.objects.filter(parent_id = 1, status = 1)
  paginator = Paginator(categories_list, 10)

try:
    page = int(request.GET.get('page', 1))
except ValueError:
    page = 1

try:
    categories = paginator.page(page)
except (EmptyPage, InvalidPage):
    categories = paginator.page(paginator.num_pages)

return render_to_response('categories_list.html', {'categories': categories})

Maybe I am just blind and/or stupid, but it just doesnt work. So any help is appreciated, thanks in advance.

Regards

© Stack Overflow or respective owner

Related posts about python

Related posts about django