数据库中的Django翻译

数据库中的Django翻译,django,translation,Django,Translation,我需要翻译数据库中的字符串,以便用户可以使用他们选择的语言查看。我不确定如何着手做这件事 在我的模板中,我有: {% for author, titleList in authorTitle.items %} <h2>"{{author}}"</h2> {% for title in titleList %} <p>"{{title}}"</p> {% endfor %} {% endfor %} 有没有办

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

在我的模板中,我有:

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

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

您必须手动添加标题的翻译。Django翻译仅适用于字符串。对于您想做的事情,请尝试django-hvad。您必须手动添加标题的翻译。Django翻译仅适用于字符串。对于你想做的事情,试试django hvad。
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 } )