SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.associate_by_email',
)
通过使用上面的代码,settings.py
我可以避免......
(1062, "Duplicate entry 'example@example.com' for key 'email'")
错误信息。
但我在网上搜索,发现这个方便的代码可以exception
放入所需的 html 页面:
[代码 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)
# 设置.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] ”的实际错误消息。