鍍金池/ 問答/Python  網(wǎng)絡(luò)安全/ flask babel 在jinja2 模版中,如何翻譯從數(shù)據(jù)庫中拿出的數(shù)據(jù)?

flask babel 在jinja2 模版中,如何翻譯從數(shù)據(jù)庫中拿出的數(shù)據(jù)?

 <h3>{{ _('%(home1.house_address)')}}</h3>

在jinja 模版中,翻譯固定的文字可以,但是怎么翻譯數(shù)據(jù)庫里面提取出來的文字?

我按照上面的寫法,發(fā)現(xiàn)不行.... 他直接把 home1.house_address 當(dāng)作要翻譯的字段處理了,實際上他是一個變量~~

        return render_template('details.html',home1 = home1)
回答
編輯回答
筱饞貓
<h3>{{ _('%(house_address)', house_address=home1.house_address) }}</h3>

這樣不就行了嗎!

2017年10月16日 05:28