将unicode字符串传递给django模板中的templatetag会导致错误

时间:2012-11-27 18:15:50

标签: django django-templates

我使用夹层来构建我的网站。在模板中我使用templatetag。当我传递给像“categorytofilter”这样的模板标签时,没关系,但是当我尝试传递unicode字符串时:

{% blog_recent_posts limit=6 category='Статьи' as recent_posts %}

我看到了错误:

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

我该如何解决? TIA!

1 个答案:

答案 0 :(得分:0)

好像你把类别传递给了ascii,而不是unicode。

尝试

{% blog_recent_posts limit=6 category=u'Статьи' as recent_posts %}

如果您对类别进行了硬编码,否则,请在传递给模板之前在视图中指定/投射它。

相关问题