2013-02-16 25 views
0

试图在Django中执行一个视图,将UserProfile挂接为我的用户配置文件模块。我想要做类似的事情:Django:在引用它之前测试UserProfile是否存在

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

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

+0

为什么不只是捕捉异常并创建一个呢? – 2013-02-16 04:43:23

+0

...我该怎么做? – atoms 2013-02-16 04:44:11

+0

[呃...](http://docs.python.org/2/tutorial/errors.html) – 2013-02-16 04:46:21

回答

0

您可以确保您的UserProfile是通过signals创建的。这里有一个相关的question

相关问题