私はdjango-allauthをdjango rest-authとともに使用しています。
ここにスタックトレースがあります:
[2016-02-15 23:45:35,093] ERROR [base:handle_uncaught_exception:256 8977] Internal Server Error: /api/rest-auth/registration/
Traceback (most recent call last):
File "/home/.../webapps/project_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/.../webapps/project_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/.../webapps/project_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/rest_framework/views.py", line 452, in dispatch
response = self.handle_exception(exc)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/rest_framework/views.py", line 449, in dispatch
response = handler(request, *args, **kwargs)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/rest_auth/registration/views.py", line 44, in post
self.form_valid(self.form)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/rest_auth/registration/views.py", line 36, in form_valid
self.get_success_url())
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/allauth/account/utils.py", line 157, in complete_signup
signal_kwargs=signal_kwargs)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/allauth/account/utils.py", line 114, in perform_login
send_email_confirmation(request, user, signup=signup)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/allauth/account/utils.py", line 286, in send_email_confirmation
signup=signup)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/allauth/account/models.py", line 60, in send_confirmation
confirmation.send(request, signup=signup)
File "/home/.../webapps/project_test/.ve/lib/python2.7/site-packages/allauth/account/models.py", line 121, in send
activate_url = reverse("account_confirm_email", args=[self.key])
File "/home/.../webapps/project_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/core/urlresolvers.py", line 578, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/home/.../webapps/project_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/core/urlresolvers.py", line 495, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'account_confirm_email' with arguments '(u'vgro7mdagterfbnqxlkihpnzs2bsp1iktwxng9vecznpeg8hcdv1eidco11tee3u',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
allauth の私の URL
私のアプリ「api」内:
api/urls.py
...
url(r'^accounts/', include('allauth.urls')),
url(r'^rest-auth/registration/account-confirm-email/(?P<key>\w+)/$',confirm_email, name='confirm_email'),
url(r'^rest-auth/', include('rest_auth.urls')),
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
...
これは、私のプロジェクト内の「api」という名前のアプリ内にあります。
私が見るシェルを使用して:
python manage.py shell
Inside api.apps.ApiConfig.ready
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>>
>>> reverse('account_confirm_email', args=['l8ig7wqo1l4ypd7uosuoxlgnv2qxf5voe5ehwcd7s46hbprzyx9qwjgeontw5un6'])
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/divkis01/webapps/instaguide_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/core/urlresolvers.py", line 578, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
File "/home/divkis01/webapps/instaguide_test/lib/python2.7/Django-1.8.7-py2.7.egg/django/core/urlresolvers.py", line 495, in _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'account_confirm_email' with arguments '('l8ig7wqo1l4ypd7uosuoxlgnv2qxf5voe5ehwcd7s46hbprzyx9qwjgeontw5un6',)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
>>>
api:account_confirm_email を使用すると、正しい URL が返されます。
>>> reverse('api:account_confirm_email', args=['l8ig7wqo1l4ypd7uosuoxlgnv2qxf5voe5ehwcd7s46hbprzyx9qwjgeontw5un6'])
u'/api/rest-auth/registration/account-confirm-email/l8ig7wqo1l4ypd7uosuoxlgnv2qxf5voe5ehwcd7s46hbprzyx9qwjgeontw5un6/'
また、 rest-auth FAQに従って、ビューで account-confirm-email をオーバーライドする必要があるため、URL をオーバーライドします。
url(r'^account-confirm-email/(?P<key>\w+)/$', TemplateView.as_view(),
name='account_confirm_email'),
私のURLで:
url(r'^rest-auth/registration/account-confirm-email/(?P<key>\w+)/$', confirm_email, name='confirm_email'),
ここに別の同様の質問があります: django-allauth がエラー「Reverse ... 引数 '()' とキーワード引数 '{}' が見つかりません」を返す
しかし、その問題はネームスペースが原因であり、私のurls.pyではallauth URLのネームスペースを作成していません。
私が間違っていることを提案してください。