9👍
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.
6👍
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.
- How to get object from PK inside Django template?
- How to efficiently serve massive sitemaps in django
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)
- Django templates stripping spaces?
- Should south migration files be added to source control?
- How to create or register User using django-tastypie API programmatically?
1👍
I am new to Django and struggled with this also. I have EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
in settings.py
. I went to the source code in my editor at .venv/Lib/site-packages/dj_rest_auth/registration/urls.py
and found the following code with a comment:
urlpatterns = [
path('', RegisterView.as_view(), name='rest_register'),
path('verify-email/', VerifyEmailView.as_view(), name='rest_verify_email'),
path('resend-email/', ResendEmailVerificationView.as_view(), name="rest_resend_email"),
# This url is used by django-allauth and empty TemplateView is
# defined just to allow reverse() call inside app, for example when email
# with verification link is being sent, then it's required to render email
# content.
# account_confirm_email - You should override this view to handle it in
# your API client somehow and then, send post to /verify-email/ endpoint
# with proper key.
# If you don't want to use API on that step, then just use ConfirmEmailView
# view from:
# django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py
re_path(
r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(),
name='account_confirm_email',
),
]
So then I overrode this in my own project level urls.py:
from django.urls import path, include, re_path
from {my_app_name}.views import CustomEmailConfirmView
urlpatterns = [
path("dj-rest-auth/registration/", include("dj_rest_auth.registration.urls")),
path("dj-rest-auth/", include("dj_rest_auth.urls")),
re_path(
r'^account-confirm-email/(?P<key>[-:\w]+)/$',
CustomEmailConfirmView.as_view(),
name='account_confirm_email',
),
]
and I created this view in views.py:
class CustomEmailConfirmView(APIView):
def get(self, request, key):
verify_email_url = 'http://localhost:8000/dj-rest-auth/registration/verify-email/'
# make a POST request to the verify-email endpoint with the key
response = requests.post(verify_email_url, {'key': key})
if response.status_code == 200:
return Response({'message': 'Email verified successfully'}, status=status.HTTP_200_OK)
else:
return Response({'message': 'Email verification failed'}, status=status.HTTP_400_BAD_REQUEST)
With this I was able to get a json response in the Django Rest Framework Browsable API:
{
"message": "Email verified successfully"
}
- Django internationalization minimal example
- Django Admin: has_delete_permission Ignored for "Delete" Action
- How to have a link in label of a form field
- Django ChoiceField populated from database values
- Avoiding MySQL deadlock in Django ORM
0👍
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",],}]
- Django Queryset of related objects, after prefiltering on original model
- How to purge all tasks of a specific queue with celery in python?
- Django eager loading in many to many