簡體   English   中英

在Django模板中將user.id轉換為user.username

[英]Convert user.id to user.username in Django template

我正在將非常酷的第三方軟件包Django-Simple-History實現到一個項目中。 根據文檔,我使用中間件來存儲哪個用戶對對象進行了更改。 這樣可以很容易地在模板中迭代,如:

{% for x in object.history.all %}
{{ x.history_date }}, {{ x.history_user_id }} <br />
{% endfor %}

我正在嘗試使用可用的user.id來獲取模板中的關聯user.username。 有什么建議么? (我還是Django / Python的新手)謝謝!

history_user保存相關用戶的ForeignKey。

您可以使用: {{ x.history_user.username }}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM