Django Reverse with arguments '()' and keyword arguments '{}' not found

Darwin Tech picture Darwin Tech · Nov 2, 2012 · Viewed 110.3k times · Source

Hi I have an infuriating problem.

I have a url pattern like this:

# mproject/myapp.urls.py

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

it works fine in the browser but for testing, when I do this in the shell:

from django.test import Client
from django.core.urlresolvers import reverse

client= Client()
response = client.get(reverse('edit_project'), project_id=4)

I get the dreaded:

NoReverseMatch: Reverse for 'edit_project' with arguments '()' and keyword arguments '{}' not found.

What am I missing here?

Answer

miki725 picture miki725 · Nov 2, 2012

You have to specify project_id:

reverse('edit_project', kwargs={'project_id':4})

Doc here