Django:在引用它之前测试UserProfile是否存在
问题描述:
试图在Django中执行一个视图,将UserProfile挂接为我的用户配置文件模块。我想要做类似的事情:Django:在引用它之前测试UserProfile是否存在
@login_required
def viewfunction (request):
if request.user.get_profile():
<< do something here >>
但是这样做会出错。是否有测试用户配置文件模块存在的最佳做法?
为什么不只是捕捉异常并创建一个呢? – 2013-02-16 04:43:23
...我该怎么做? – atoms 2013-02-16 04:44:11
[呃...](http://docs.python.org/2/tutorial/errors.html) – 2013-02-16 04:46:21