【发布时间】:2014-10-27 18:45:22
【问题描述】:
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.associate_by_email',
)
通过在settings.py 中使用上述代码,我可以避免...
(1062, "Duplicate entry 'example@example.com' for key 'email'") 错误信息。
但我在网上搜索,发现这个方便的代码可以在所需的 html 页面中抛出 exception:
[代码 1]: #backends.py
class MySocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
def process_exception(self, request, exception):
msg = None
if #no duplicate email:
return HttpResponse("# catched exception")
else:
# processing msg here
return render_to_response(# html, {msg}, context)
#settings.py
MIDDLEWARE_CLASSES = (
'frontend.backends.MySocialAuthExceptionMiddleware'
)
我的问题是solved 基于上面的代码。但在之前我使用以下代码处理了另一个功能,它与上述概念完全不同。
[代码 2]:
def function(request):
#actual code here
return HttpResponse('msg here')
但是在运行上面的代码时,我收到了类似的错误消息,
tuple index out of range 在这个MySocialAuthExceptionMiddleware..
实际上这不是上述代码的正确错误信息。此信息与“[Code 1]”的代码有关。
那么,我怎样才能得到“[Code 2]”的实际错误信息。
【问题讨论】:
-
因为那是引发异常的地方,但是您不能查看回溯以找到根本原因吗?
-
@Knyght 我编辑了我的问题更易于阅读......
-
@Knyght
code 1仅用于处理该特定异常。但是为什么code 2错误消息会转到MySocialAuthExceptionMiddleware。
标签: python django django-views python-social-auth