Receive request from urls.py

1

In the user activation system of my platform, the user accesses a link in the following way:

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

My file 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/([a-zA-Z0-9]{15})/([\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', homePageView.activate, name='activate')
]

My method of the views.py

class homePageView(TemplateView):
    template_name = 'index.html'
    def activate(self, request, code_, email_):
        try:
            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')

And of course, since urls.py receives two parameters and the activate method asks for three ...

How could I then have the method receive the request.

Thanks

    
asked by XBoss 29.06.2018 в 20:52
source

0 answers