1

アクセントのある文字に問題があります。áDjango 管理者は、" "のような形式にエンコードせずにデータを保存します

例: "Canción" のような単語を使用しようとしている場合、Canción ではなく、次のように保存しCanciónます。

私は私の設定に持っています:DEFAULT_CHARSET = 'utf-8'

私は私のmysqlデータベースに持っています:utf8_general_ci

私はSociableアプリを使用しています:

{% load sociable_tags %}

{% get_sociable Facebook TwitThis Google MySpace del.icio.us YahooBuzz Live as sociable_links with url=object.get_absolute_url title=object.titulo %}
{% for link in sociable_links %}
    <a href="{{ link.link }}"><img alt="{{ link.site }}" title="{{ link.site }}" src="{{ link.image }}" /></a>
{% endfor %}

しかし、object.titulo (記事のタイトル) にアクセント付きの単語が含まれていると、エラーが発生します。

Traceback:
File "C:\wamp\bin\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "C:\wamp\bin\Python26\lib\site-packages\django\views\generic\date_based.py" in object_detail
  366.     response = HttpResponse(t.render(c), mimetype=mimetype)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in render
  173.             return self._render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in _render
  167.         return self.nodelist.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "C:\wamp\bin\Python26\lib\site-packages\django\template\debug.py" in render_node
  72.             result = node.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in _render
  167.         return self.nodelist.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "C:\wamp\bin\Python26\lib\site-packages\django\template\debug.py" in render_node
  72.             result = node.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\django\template\__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "C:\wamp\bin\Python26\lib\site-packages\django\template\debug.py" in render_node
  72.             result = node.render(context)
File "C:\wamp\bin\Python26\lib\site-packages\sociable\templatetags\sociable_tags.py" in render
  37.                 'link': sociable.genlink(site, **self.values),
File "C:\wamp\bin\Python26\lib\site-packages\sociable\sociable.py" in genlink
  20.         values['title'] = quote_plus(kwargs['title'])
File "C:\wamp\bin\Python26\lib\urllib.py" in quote_plus
  1228.         s = quote(s, safe + ' ')
File "C:\wamp\bin\Python26\lib\urllib.py" in quote
  1222.     res = map(safe_map.__getitem__, s)

Exception Type: TemplateSyntaxError at /noticia/2010/jun/10/matan-domingo-paquete-en-la-avenida-san-vicente-de-paul/
Exception Value: Caught KeyError while rendering: u'\xfa'

ありがとう!

4

2 に答える 2

4

問題は、sociable がurllib.quote_plusユニコードセーフではない python 2.6 のデフォルトの実装を使用していることです。Unicode 対応の django を使用する必要がdjango.utils.http.urlquote_plusあります。

質問の他の部分に答えるために、エスケープされた文字列をデータベースに保存したい場合 (これはお勧めしません)、モデルの save メソッドでエスケープを行うメソッドを呼び出すことができます。ただし、私が認識している unicode-to-html-entity エスケープを行う組み込みの python または django ユーティリティはありません。ただし、Googleですばやく検索すると、いくつか表示されます。繰り返しますが、これを行うことはお勧めしません。Django は Unicode セーフであり、その事実を利用することをお勧めします!

于 2010-06-14T19:59:08.060 に答える
1

django-sociableこれは、それ自体が誤った処理を行うバグunicodeです。このバグを報告してから、開発者と協力して修正することをお勧めします。

于 2010-06-14T19:56:35.013 に答える