Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoReverseMatch #6

Open
josephlee94 opened this issue Dec 24, 2018 · 5 comments
Open

NoReverseMatch #6

josephlee94 opened this issue Dec 24, 2018 · 5 comments

Comments

@josephlee94
Copy link

I'm trying your email verification on my site, but I get this error:

NoReverseMatch
Reverse for 'activate' with keyword arguments '{'uidb64': b'MTM', 'token': '52d-53339dd970c622ae0d32'}' 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})/$']
/root/anaconda3/lib/python3.7/site-packages/django/urls/resolvers.py in _reverse_with_prefix, line 622
/root/anaconda3/bin/python
3.7.0
['/root/gtd', '/root/anaconda3/lib/python37.zip', '/root/anaconda3/lib/python3.7', '/root/anaconda3/lib/python3.7/lib-dynload', '/root/anaconda3/lib/python3.7/site-packages']

The error seemed to be at:

http://{{ domain }}{% url 'activate' uidb64=uid token=token %}

@lenheard
Copy link

I'm getting the same problem...
django.urls.exceptions.NoReverseMatch: Reverse for 'activate' with keyword arguments '{'uidb64': b'MTE', 'token': '54r-56fbea658aa4822ce6b3'}' not found. 1 pattern(s) tried: ['activate/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$']
[19/Mar/2019 18:31:16] "POST /signup/ HTTP/1.1" 500 135577

How did you solve it?

@sodrooome
Copy link

if you use django version 2.0 or above, you should use decode() after encoding the uid. As you can see through this code like :

message = render_to_string('account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
                'token': account_activation_token.make_token(user),
            })

Or you can use force_text that compatible with django version 1.11, 2.0 or higher. May it help you

@CatarinaLopes
Copy link

i used this solution 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(), and now i have an 'str' object has no attribute 'decode'
what to do?

@UngeheurenUngeziefer
Copy link

There is no need to use decode() function here, it should be just:
'uid': urlsafe_base64_encode(force_bytes(user.pk))

You should use context args in activation function as well:

context = {'uidb64': uidb64, 'token': token} 
return render(request, 'users/thank_confirm.html', context)

And the main problem is in the urls of your app that including activation view. You should use slug:
path('activate/<slug:uidb64>/<slug:token>/', views.activate, name='activate')
and don't forget to import path if you are using only urls
from django.urls import path

@albarran99
Copy link

I’m trying what you propose but it gives me another problem

my views.py

class ActivateAccount(View):

def get(self, request, uidb64, token, *args, **kwargs):
    context = {
        'uidb64': uidb64,
        'token': 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.profile.email_confirmed = True
        user.save()
        login(request, user)
        messages.success(request, 'Your account have been confirmed.')
        return render(request, 'password_reset_form.html', context)

    else:
        messages.warning(request, 'The confirmation link was invalid, possibly because it has already been used.')
        return redirect('home')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants