在Django中运行测试时出现NoReverseMatch错误

时间:2013-04-11 15:48:37

标签: python django

我正在使用python django 我在运行tests.py时遇到错误 这是什么意思:

Traceback (most recent call last):
  File "/home/hala/Desktop/lasting/sharesoft-13/project/tager/tager_www/tests.py", line 82, in test_saving_comments
    response=c.get(reverse('adingcomment', kwargs={'post_id' : 1, 'content':'hjhgh'}))
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 496, in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 416, in _reverse_with_prefix
    "arguments '%s' not found." % (lookup_view_s, args, kwargs))
NoReverseMatch: Reverse for 'adingcomment' with arguments '()' and keyword arguments '{'content': 'hjhgh', 'post_id': 1}' not found.

2 个答案:

答案 0 :(得分:1)

这意味着Django无法找到与该特定路径名和参数匹配的路由,因此无法通过反转路由生成URL。

也许adingcomment是一个错字,应该是addingcomment而不是?

答案 1 :(得分:0)

reverse('adingcomment', kwargs={'post_id' : 1, 'content':'hjhgh'})无法找到网址路径。

也许您注册了addingcomment路线?您需要检查路由的名称和提供的参数,以匹配您注册的现有路由。有关详细信息,请参阅Reverse resolution of URLs文档。

相关问题