【发布时间】:2014-06-02 10:56:40
【问题描述】:
我在我的网页中使用了 django_tables2 来显示一个表格。
我的这个表的代码在tables.py中:
import django_tables2 as tables
from django.utils.translation import ugettext_lazy
from django.utils.encoding import force_text
class patchTable(tables.Table):
release_version=tables.Column(verbose_name=force_text(ugettext_lazy("Release Version"),orderable=False, localize=True)
patch_version=tables.Column(verbose_name=force_text(ugettext_lazy("Patch Version")),orderable=False, localize=True)
release_date = tables.Column(verbose_name=force_text(ugettext_lazy("Release Date")),orderable=False, localize=True)
upload_date = tables.Column(verbose_name=force_text(ugettext_lazy("Upload Date")),orderable=False, localize=True)
apply_status = tables.Column(verbose_name=force_text(ugettext_lazy("Status")),orderable=False, localize=True)
installation_date = tables.Column(verbose_name=force_text(ugettext_lazy("Installation Date")),orderable=False, localize=True)
在我的 views.py 方法中,我正在执行“从 myapp.tables 导入 patchTable”,然后更新表格内容、分页并呈现到模板。
上面的代码工作正常,并以我当前正在使用的语言显示列名(在 runserver 命令期间)。但是如果我更改 HTML 页面上的语言选择,页面上的所有其他内容都会被翻译,但该表的列名不会。
如果我重新启动 django 服务器(cntrl+c 和 python2.7 管理 runserver 0.0.0.0:8060),那么这些名称会更改为当前语言,但它们不会在语言选择时动态发生。
我尝试使用 1)“ugettext”2)“ugettext_lazy”(这会引发异常:'Lazy 对象返回了意外类型。)'3)“force_text”和“ugettext_lazy”组合。但他们没有工作。谁能给我一个可行的方法吗?
顺便说一下,我使用的是 Python 2.7、Django 1.5.1 和 Django 开发服务器。所有本地化设置要求都包含在项目中,settings.py 有“USE_L10N = True”和“USE_I18N = True”。 任何帮助,将不胜感激。如果这个问题需要更多细节,请告诉我。提前致谢。
【问题讨论】:
标签: python django django-tables2