Ali
Ali

Reputation: 6968

Reverse for '' with arguments and keyword arguments '' not found

I have following views in my light_shop app:

def order_list(request, error_message):
    context = {}
    context['type'] = 'order-list'
    context['error_message'] = error_message
    update_context(request, context, add_order_list=True)
    return render(request, 'light_shop/order_list.html', context)

def add_to_list(request, prd_id):
    add_product_to_list(request, prd_id)
    return HttpResponseRedirect(reverse('light_shop.views.order_list', args=('test_error',)))

and this is urls.py

urlpatterns = patterns('light_shop',
    ...
    url(r'^add-to-list/(?P<prd_id>\d+)/$', 'views.add_to_list'),
    url(r'^show-list/()$', 'views.order_list'),
    ...

)

but I get error: Reverse for 'light_shop.views.order_list' with arguments '('test_error',)' and keyword arguments '{}' not found. in add_to_list second line.

I even test naming parameter in url pattern for order_list. (e.g. url(r'^show-list/(?P<error_message>)$', 'views.order_list') and changing reverse function to reverse('light_shop.views.order_list', kwargs={'error_message':'error_message'})) but again same error is occurred.

I'm using Django 1.5 and I look this page for documantation and I am really confused what is the problem: https://docs.djangoproject.com/en/1.5/topics/http/urls/

Upvotes: 1

Views: 1925

Answers (1)

karthikr
karthikr

Reputation: 99680

The problem is with the URL pattern

url(r'^show-list/()$', 'views.order_list'),

which seems to be incomplete.

Update it to (Basically, specify a Named Group)

url(r'^show-list/(?P<error_message>[\w_-]+)$', 'views.order_list'),

Upvotes: 3

Related Questions