如何访问Django模板中的用户个人资料? [英] How to access the user profile in a Django template?

查看:125
本文介绍了如何访问Django模板中的用户个人资料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AUTH_PROFILE_MODULE

I'm storing some additional per-user information using the AUTH_PROFILE_MODULE.

我们可以在Django模板中使用 {{request.user}} 但是我们如何访问配置文件中的字段,因为只能通过函数 user.get_profile()

We can access the user in a Django template using {{ request.user }} but how do we access fields in the profile since the profile is only accessible via a function user.get_profile() ?

是否真的需要每次将配置文件显式传递到模板?

Is it really required to explicitly pass the profile into the template every time?

推荐答案

使用 {{request.user.get_profile.whatever}} 。 Django的模板语言自动调用可调用的东西 - 在这种情况下, .get_profile()方法。

Use {{ request.user.get_profile.whatever }}. Django's templating language automatically calls things that are callable - in this case, the .get_profile() method.

这篇关于如何访问Django模板中的用户个人资料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆