django get_profile错误 [英] django get_profile error
本文介绍了django get_profile错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我已经在settings.py
I want to get my userprofile id in the views i have already included below in settings.py
AUTH_PROFILE_MODULE = 'users.UserProfile'
查看代码:
def savecontent(request):
try:
logging.debug("=========================== in save content")
logging.debug(dir(request.user))
my_id = request.user.get_profile().id
logging.debug(my_id)
错误是:
2012-07-17 13:00:00,564 ERROR Error while saing content
Traceback (most recent call last):
File "/opt/labs/labs_site/content/views.py", line 21, in savecontent
my_id = request.user.get_profile().id
File "/opt/labs/django/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'AnonymousUser' object has no attribute 'get_profile'
推荐答案
AttributeError: 'AnonymousUser' object has no attribute 'get_profile'
您必须拥有经过身份验证的用户才能检索个人资料,这是您的问题
You must have an authenticated user to retrieve a profile, that's your problem
@login_required
def foo(request):
profile_id = request.user.get_profile().id
这篇关于django get_profile错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文