0

Mi fichero urls.py:

#home/urls.py
from django.urls import path, re_path
from home.views import homePageView

urlpatterns = [
    path('',homePageView.as_view(),name='home'),
    re_path('activate/(?P<code_>[a-zA-Z0-9]{15})/(?P<email_>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', homePageView.activate, name='activate')
]

Método activate en views.py:

class homePageView(TemplateView):
    template_name = 'index.html'
    def activate(self, request, *args, **kwargs):
        try:
            email_ = kwargs['email_']
            code_ = kwargs['code_']
            user = Usuario.objects.get(email=email_,activated_code=code_)
            code = user.activated_code
            if (not user.activated) and code == code_:
                user.activated = True
                user.save()
                messages.success(request, 'User activated successfully')
            else:
                messages.error(request,'Error activating user, please, use the contact form to contact us')
        except Usuario.DoesNotExist:
            messages.error(request,'Error activating user, please, use the contact form to contact us')
        return redirect('home')

al entrar en una url como esta:

http://127.0.0.1:8000/activate/aE8w3fqEsoLMykQ/[email protected]/

me lanza el siguiente error:

activate() missing 1 required positional argument: 'request'

1 respuesta 1

0

Tenía que utilizar el método así:

def activate(request, *args, **kwargs):

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.