外键访问数据Django

时间:2018-12-24 14:35:18

标签: django django-models django-templates django-views

我想使用user_role在模板中显示# Otsu Segmentation # Read image image = img_as_ubyte(imread('../../Samples/sunflower19.jpeg')) # Convert image to gray and calculate histogram grey = img_as_ubyte(rgb2gray(image)) hist = np.histogram(image, bins=np.arange(0, 256)) # Calculate threshold and remove background threshold = threshold_otsu(grey) image_br = deepcopy(image) image_br[grey < threshold] = 0

role_title

1 个答案:

答案 0 :(得分:2)

有很多方法可以做到这一点。喜欢:

对于UserDetailView模板:

# View

class UserDetailView(DetailView):
    model = User
    ...

# In Template

{{ object.userprofile.user_role.role_title }}

对于UserProfileDetailView

class UserProfileDetailView(DetailView):
    model = UserProfile
    ...

# In Template

{{ object.user_role.role_title }}

对于任何已登录的用户:

{{ user.userprofile.user_role.role_title }}