Django从数据库翻译

时间:2017-03-22 20:49:45

标签: django translation

我的数据库中有我需要翻译的字符串,以便用户可以用他们选择的语言查看。我不确定如何去做这件事。

在我的模板中,我有:

{% for author, titleList in authorTitle.items %}
    <h2>"{{author}}"</h2>
    {% for title in titleList %}
        <p>"{{title}}"</p>
    {% endfor %}
{% endfor %}

views.py我有:

authorList = list(TblBooks.objects.values_list("authorid__authorname", flat = True).distinct())
authorBook = {} 
for author in authorList:
    authorBook[author] = TblBooks.objects.filter(authorid__authorname = author).order_by("title")
return render(request, 'index.html', {  'authorTitle': authorBook } )

有没有办法从视图或模板翻译标题。如果没有,我该如何翻译标题?

0 个答案:

没有答案