反向找不到

时间:2018-02-02 13:27:48

标签: django

我使用Django 1.7并且我有这种URL模式:

url(r'^account/unsubscribe/(?P<user_id>[^/.]+)/(?P<token>[\w.:\-_=]+)$', views.unsubscribe, name='account-unsubscribe')

我的项目代码中有这个:

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, })

为什么我在调用create_unsubscribe_link时得到这个?:

NoReverseMatch: Reverse for 'account-unsubscribe' with arguments '()' and keyword arguments '{'token': '1ehbA0:czK8xR8IGiGu7WdEuYRkYigXBzI', 'user_id': <TelespineUser: name: demo@telespine.com, id: 1>}' not found. 1 pattern(s) tried: ['api/v1/account/unsubscribe/(?P<user_id>[^/.]+)/(?P<token>[\\w.:\\-_=]+)$']

1 个答案:

答案 0 :(得分:2)

您的ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("annie.gapp").getFile()); // CorpusController application = (CorpusController) PersistenceManager.loadObjectFromFile( //new File("annie.gapp")); CorpusController application = (CorpusController) PersistenceManager.loadObjectFromFile( file); 参数是TelespineUser对象,而不是user_id参数。

您需要像这样更改:

id