0

I'm trying to add an Email confirmation feature to my Django project, where a user has to confirm it's email using the link provided by the site.

I already added the view, the url and a template, but i keep getting the error:

Reverse for 'activate' not found. 'activate' is not a valid view function or pattern name.

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

I don't know where this error is coming from, i think i defined my view properly and added it to my urls.py, i'm following this tutorial.

Here is my view:

def activate(request, uidb64, token):
    try:
        uid = force_text(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()
        login(request, user)
        # return redirect('home')
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
    else:
        return HttpResponse('Activation link is invalid!')

The url:

 from .views import activate

    path("activate/<slug:(?P<uidb64>[0-9A-Za-z_\-]+)>/<slug:(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$>",
        views.activate, name='activate'),

And acc_active_email.html

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

Any advice is appreciated.

Jack022
  • 867
  • 6
  • 30
  • 91
  • where is that urls.py file? how is it included in the main urls.py? – dirkgroten May 01 '19 at 16:35
  • It's in the same folder! – Jack022 May 01 '19 at 16:36
  • The code in the update `[0-9A-Za-z_\-]+)>` is an incorrect mixture of old and new syntax. Read the answer I linked to carefully. – Alasdair May 01 '19 at 16:46
  • 2
    If you have `app_name = 'myapp'` in the app's `urls.py`, then you'll need it in the `{% url tag %}`, e.g. `{% url 'myapp:activate' uidb64=uid token=token %}` – Alasdair May 01 '19 at 16:47
  • Hey @Alasdair what you suggested worked. Now i'm getting this error, though: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials f8sm2974390wmb.32 - gsmtp') – Jack022 May 01 '19 at 17:05
  • That's a separate issue so I can't help with that. Start with the suggestions on the page linked to in the error message. If you search Stack Overflow for gmail and Django some of the answers might help. – Alasdair May 01 '19 at 17:22

0 Answers0