小编典典

找不到带有参数'()'和关键字参数'{}'的Django Reverse

django

我有这样的网址格式:

# mproject/myapp.urls.py

url(r'^project/(?P<project_id>\d+)/$','user_profile.views.EditProject',name='edit_project'),

它在浏览器中可以正常工作,但是当我在外壳中执行此操作时,可以进行测试:

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.

我在这里想念什么?


阅读 460

收藏
2020-03-31

共1个答案

小编典典

你必须指定project_id:

reverse('edit_project', kwargs={'project_id':4})
2020-03-31