SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.associate_by_email',
)
例外...的Django通過使用<code>settings.py</code>上面的代碼中我能避免提高地方
(1062, "Duplicate entry '[email protected]' 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)
#設置.py
MIDDLEWARE_CLASSES = (
'frontend.backends.MySocialAuthExceptionMiddleware'
)
根據上面的代碼我的問題是solved
。但在以前我使用下面的代碼與另一個功能合作,它與上述概念完全不同。
[代碼2]:
def function(request):
#actual code here
return HttpResponse('msg here')
但是在運行上面的代碼,以及我得到在此MySocialAuthExceptionMiddleware
錯誤消息等,
tuple index out of range
..
其實對於上面的代碼,這是不正確的錯誤消息。此消息與代碼「[代碼1]「。
然後,我怎樣才能得到「[代碼2]」的實際錯誤信息。
因爲這就是引發異常的地方,但是不能查看回溯來找出根本原因嗎? – 2014-09-03 11:09:53
@Knyght我編輯我的問題更友好閱讀.. – 2014-09-03 11:46:24
@Knyght'代碼1'是專爲處理該特定的異常而已。但爲什麼'代碼2'錯誤消息去'MySocialAuthExceptionMiddleware'。 – 2014-09-03 11:52:32