Django utf-8和django-mailer陌生

来自trunk的最新django邮件http://github.com/jtauber/django-mailer/tree/master/docs/

用Postgresql 8.4,sqlite3测试

模板

{{ title }}

forms.py

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

if "mailer" in settings.INSTALLED_APPS:
    from mailer import send_mail
else:
    from django.core.mail import send_mail


...
        body_txt = render_to_string(
            'mails/share_deal/email_body.txt',
            {

                'title':u"éééààà",

            }
        )

        send_mail( "",  body_txt , "foo@ff.ff",  ["bar@kl.fd"],  fail_silently=True)

错误

环境:

请求方法:POST请求URL:http://localhost:8000/deals/share/ Django版本:1.2 SVN-13596 Python版本:2.6.5已安装的应用程序:['django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','django.contrib.messages','django.contrib.admin','django_extensions','django.contrib.markup','django.contrib.comments','ajaxcomments','mailer','profiles','tagging' ,'wmd','core','deals']已安装的中间件:('django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/home/gregory/.virtualenvs/alpha/src/django/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/gregory/projects/casadeal/casadeal/core/decorators.py" in wrap
  12.         return f(request, *args, **kwargs)
File "/home/gregory/.virtualenvs/alpha/src/django/django/views/decorators/http.py" in inner
  37.             return func(request, *args, **kwargs)
File "/home/gregory/projects/casadeal/casadeal/deals/views.py" in share_deal
  22.             form.send_mail()
File "/home/gregory/projects/casadeal/casadeal/deals/forms.py" in send_mail
  89.             fail_silently=True)
File "/home/gregory/.virtualenvs/casadeal/src/django-mailer/mailer/__init__.py" in send_mail
  45.                  priority=priority).save()
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/base.py" in save
  435.         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/base.py" in save_base
  528.                     result = manager._insert(values, return_id=update_pk, using=using)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/manager.py" in _insert
  195.         return insert_query(self.model, values, **kwargs)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/query.py" in insert_query
  1479.     return query.get_compiler(using=using).execute_sql(return_id)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/sql/compiler.py" in execute_sql
  783.         cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/sql/compiler.py" in execute_sql
  727.         cursor.execute(sql, params)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/backends/util.py" in execute
  15.             return self.cursor.execute(sql, params)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/backends/postgresql_psycopg2/base.py" in execute
  44.             return self.cursor.execute(query, args)

Exception Type: DatabaseError at /deals/share/
Exception Value: ERREUR:  séquence d'octets invalide pour l'encodage « UTF8 » : 0xe9e9e9
HINT:  Cette erreur peut aussi survenir si la séquence d'octets ne correspond pas
au jeu de caractères attendu par le serveur, le jeu étant contrôlé par
« client_encoding ».

Basically it says that the encoding was not valid for UTF8 and contained   0xe9e9e9

这看起来很奇怪,

有关它可能来自何处的任何提示?

回答(1)

2 years ago

U 00E9是带有急性的拉丁文小写字母E.

这可能是问题的根源(不一定是原因): 'title':u"éééààà", .

原因可能是 your_title.encode('latin1').decode('utf8') (当然不是一步到位) .