我遇到了同样的问题,至少在这一点上,创建包装视图是处理这种情况的最佳方法。这是我的完成方式:
def social_auth_login(request, backend):
"""
This view is a wrapper to social_auths auth
It is required, because social_auth just throws ValueError and gets user to 500 error
after every unexpected action. This view handles exceptions in human friendly way.
See https://convore.com/django-social-auth/best-way-to-handle-exceptions/
"""
from social_auth.views import auth
try:
# if everything is ok, then original view gets returned, no problem
return auth(request, backend)
except ValueError, error:
# in case of errors, let's show a special page that will explain what happened
return render_to_response('users/login_error.html',
locals(),
context_instance=RequestContext(request))
您必须为此进行设置url
:
urlpatterns = patterns('',
# ...
url(r'^social_auth_login/([a-z]+)$', social_auth_login, name='users-social-auth-login'),
)
然后像以前一样在模板中使用它:
<a href="{% url 'users-social-auth-login' "google" %}">Log in with Google</a>
希望这会有所帮助,即使是在提出问题两个月后:)