嗨,我有一个令人愤怒的问题。
我有一个这样的网址模式:
# mproject/myapp.urls.py url(r'^project/(?P<project_id>\d+)/$','user_profile.views.EditProject',name='edit_project'),
它在浏览器中运行良好,但对于测试,当我在 shell 中执行此操作时:
from django.test import Client from django.core.urlresolvers import reverse client= Client() response = client.get(reverse('edit_project'), project_id=4)
我得到了可怕的:
NoReverseMatch: Reverse for 'edit_project' with arguments '()' and keyword arguments '{}' not found.
我在这里想念什么?
您必须指定project_id:
project_id
reverse('edit_project', kwargs={'project_id':4})
文档在这里