Reputation: 383
I'm using Django 1.7 and I have this URL pattern:
url(r'^account/unsubscribe/(?P<user_id>[^/.]+)/(?P<token>[\w.:\-_=]+)$', views.unsubscribe, name='account-unsubscribe')
And I have this in my project code:
def create_unsubscribe_link(self):
email, token = self.user.email_notifications.make_token().split(":", 1)
user_id = TelespineUser.objects.get(email=email)
return reverse('account-unsubscribe',
kwargs={'user_id': user_id, 'token': token, })
Why do I get this while calling create_unsubscribe_link?:
NoReverseMatch: Reverse for 'account-unsubscribe' with arguments '()' and keyword arguments '{'token': '1ehbA0:czK8xR8IGiGu7WdEuYRkYigXBzI', 'user_id': <TelespineUser: name: [email protected], id: 1>}' not found. 1 pattern(s) tried: ['api/v1/account/unsubscribe/(?P<user_id>[^/.]+)/(?P<token>[\\w.:\\-_=]+)$']
Upvotes: 0
Views: 79
Reputation: 4643
Your user_id
parameter is a TelespineUser object not its id
parameter.
You need to change it like this:
def create_unsubscribe_link(self):
email, token = self.user.email_notifications.make_token().split(":", 1)
user_id = TelespineUser.objects.get(email=email).id
return reverse('account-unsubscribe',
kwargs={'user_id': user_id, 'token': token, })
Upvotes: 2