ImproperlyConfigured at /rest-auth/registration/account-confirm-email

梦想与她 提交于 2020-12-08 06:28:25

问题


I'm using django-rest-auth for user signup and verify email. I'm able to successfully send the email when a user signs up. Howvever, on email verification, I'm getting this error with the following traceback:

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in get
  155.         return self.render_to_response(context)
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in render_to_response
  130.             template=self.get_template_names(),
File "/Library/Python/2.7/site-packages/django/views/generic/base.py" in get_template_names
  142.                 "TemplateResponseMixin requires either a definition of "

Exception Type: ImproperlyConfigured at /rest-auth/registration/account-confirm-email/vjohhnrf6xpkmn1jxbzaopdn0g79tdyofumeeuyuehcuja8slyz7nzq1idyifcqk/
Exception Value: TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'

Any idea on how to fix this ?


回答1:


While Ricardo's answer is correct, it didn't do much to help me solve my problem. This is what I needed to do for my master urls.py:

from allauth.account.views import confirm_email
.....
url(r'^accounts-rest/registration/account-confirm-email/(?P<key>.+)/$', confirm_email, name='account_confirm_email'),

Make sure that the beginning of the url spec starts with whatever path you are using for allauth REST calls.

Of course, the above is for using the built-in view handling the confirmation.




回答2:


When you use confirmation email you have two ways to do it.

Using the specified by the API or creating yours. By default it uses django-allauth and a TemplateView on reverse can be used.

If you create yours, you may have to override account_confirm_email and then post to verification_mail.

In urls.py it is defined just reverse so, depending on what you are trying to do you will have first to create your own account_confirm_email, get the required key and post it to verify-email. Here there is more information about this bug.




回答3:


For the new Django versions re_path url resolver method works properly with this (?P.+) url regex.

from django.urls import re_path

re_path('rest-auth/registration/account-confirm-email/(?P<key>.+)/', CustomConfirmEmailView.as_view(), name='account_confirm_email')

Also I have customized allauth ConfirmEmailView get() method in order to redirect properly

from allauth.account.views import ConfirmEmailView
from django.contrib.auth import get_user_model

class CustomConfirmEmailView(ConfirmEmailView):
    def get(self, *args, **kwargs):
        try:
            self.object = self.get_object()
        except Http404:
            self.object = None
        user = get_user_model().objects.get(email=self.object.email_address.email)
        redirect_url = reverse('user', args=(user.id,))
        return redirect(redirect_url)



回答4:


I also have the problem as I read the tutorialHere is the link ,it shows the problem as TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()'
solution:

I change the location of templates filer and change the templates in the setting.py

   1. In the App_Name file,I add the New folder Named:templates                                  
   2. In the settings.py: TEMPLATES = [{'DIRS': [BASE_DIR+"/templates",],}]           


来源:https://stackoverflow.com/questions/29725369/improperlyconfigured-at-rest-auth-registration-account-confirm-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!