Send mail with activate url from user

Use GOOGLE translate “Italian to English”

Salve, vorrei sapere perché ottengo questo errore:

NoReverseMatch at /accounts/signup/

Reverse for ‘activate’ with keyword arguments ‘{‘uidb64’: ‘NA’, ‘token’: ‘cakqod-a0a402b24e6f050c87abb1681556ac09’}’ not found. 1 pattern(s) tried: [‘accounts/activate/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/’]

Request Method: POST
Request URL: http://localhost:8080/accounts/signup/
Django Version: 4.2.14
Exception Type: NoReverseMatch
Exception Value: Reverse for ‘activate’ with keyword arguments ‘{‘uidb64’: ‘NA’, ‘token’: ‘cakqod-a0a402b24e6f050c87abb1681556ac09’}’ not found. 1 pattern(s) tried: [‘accounts/activate/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/’]

re_path(r’^activate/(?P[0-9A-Za-z_-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/', views.activate, name=‘activate’),

Ho recuperato un vecchio codice della 3.2 che nella 3.2 era solamente path.

qui nella 4.2 non mi funziona.

il codice della views è questo:

from django.shortcuts import  get_object_or_404
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import UpdateView, DetailView, CreateView
from django.urls import reverse_lazy
from django.contrib.auth import get_user_model
from . forms import ProfileUpdate
from django.shortcuts import redirect
from django.contrib.auth.views import LoginView, LogoutView, PasswordResetView, PasswordResetConfirmView,  PasswordResetDoneView, PasswordResetCompleteView, PasswordChangeView, PasswordChangeDoneView
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode  
from .token import account_activation_token  
from django.core.mail import EmailMessage  
from django.template.loader import render_to_string  
from django.http import HttpResponse  
from django.contrib.sites.shortcuts import get_current_site  
from django.utils.encoding import force_str, force_bytes
from . import forms

User = get_user_model()

class LoginView(LoginView):
    form_class = forms.AuthenticationForm

class LogoutView(LogoutView):
    pass

# class signupView(CreateView):
#     form_class = forms.UserCreationForm
#     template_name = "accounts/signup.html"
#     success_url = reverse_lazy("home")

class signupView(CreateView):
    form_class = forms.signupForm
    template_name = "accounts/signup.html"
    success_url = reverse_lazy("home")

    def form_valid(self, form): 
        user = form.save(commit=False)  
        user.is_active = False  
        user.save()  
        current_site = get_current_site(self.request)  
        mail_subject = 'Activation link has been sent to your email id'  
        message = render_to_string('accounts/acc_active_email.html', {  
            'user': user,  
            'domain': current_site.domain,  
            'uid':urlsafe_base64_encode(force_bytes(user.pk)),  
            'token':account_activation_token.make_token(user),  
        })  
        to_email = form.cleaned_data.get('email')  
        email = EmailMessage(  
                    mail_subject, message, to=[to_email]  
        )  
        email.send()  
        return HttpResponse('Please confirm your email address to complete the registration')  


def activate(request, uidb64, token):  
    User = get_user_model()  
    try:  
        uid = force_str(urlsafe_base64_decode(uidb64))  
        user = User.objects.get(pk=uid)  
    except(TypeError, ValueError, OverflowError, User.DoesNotExist):  
        user = None  
    if user is not None and account_activation_token.check_token(user, token):  
        user.is_active = True  
        user.save()  
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')  
    else:  
        return HttpResponse('Activation link is invalid!')

avete idea come posso convertirlo per far funzionare nella 4.2?

Questo l’html:

{% autoescape off %}  
Hi {{ user.username }},  
Please click on the link to confirm your registration,  
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}  
{% endautoescape %}  

grazie mille.

where is urls.py code include url name that activate?