Django:在引用i之前测试UserProfile是否存在

2024-10-08 18:30:48 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试在Django中创建一个视图,将UserProfile连接到我的用户概要模块中。我想做些类似的事情:

@login_required
def viewfunction (request):
   if request.user.get_profile():
      << do something here >>

但这样做会出错。是否有测试用户配置文件模块存在的最佳实践?在


Tags: 模块django用户视图getifrequestdef

热门问题