小编MWh*_*man的帖子

无法访问 Django 模板中的 UserProfile 模型字段。试过{{ user.userprofile }}

我试图导入 {{ user.userprofile. }} 和 {{ user.userprofile }} 没有成功。在 django shell 中,我可以使用 UserProfile.objects.all() 访问用户配置文件。

{{ 用户。}} 工作正常,所以我认为这是我的模型的问题,但我已经检查了 Django 文档“模型”、“数据库查询”和“模型实例引用”以及相关的 S/O 帖子,但如果它是我的模型这就是问题所在,我不知道还能搜索什么。

谢谢

模型.py

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver

class UserProfileManager(models.Manager):
    pass

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user')
    can_inst_nat = models.BooleanField(verbose_name='I can explain grammar and word usage to people in my NATIVE language.', default=False)
    can_inst_tar = models.BooleanField(verbose_name='I can explain grammar and word usage to people in my TARGET language.', …
Run Code Online (Sandbox Code Playgroud)

python django model templatetags user-profile

2
推荐指数
1
解决办法
590
查看次数

标签 统计

django ×1

model ×1

python ×1

templatetags ×1

user-profile ×1