Skip to main content
 首页 » 编程设计

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

2025年05月04日35telwanggs

我正在使用 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. 

请您参考如下方法:

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

也许 adingcomment 是一个拼写错误,应该用 addingcomment 代替?