我想在登录后在主页上显示用户名和姓氏,而不是用户。但是我的用户模型是由另一种包含姓名和姓氏字段的表单扩展的。
{% if user.is_authenticated %}
<p>Welcome, {{ user.username }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
这将显示用户名。但我的第二个表单有一个带有用户模型的 OnetoOneField 。我尝试了类似 user.form2.name 的方法,但这不是解决方案。
最佳答案
{% if request.user.is_authenticated %}
<p>Welcome, {{ request.user.<name_of_one_to_one_model_in_lower_case>.surname }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
关于python - Django登录后如何在主页显示用户名和姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48466725/