[Answer]-NoReserveMatch error when passing multiple parameters to template

1👍

✅

Try a view similar to the following:

def state(request, country_id, state_id):
    my_state = State.objects.all()[0]
    my_country = Country.objects.all()[0]
    return render_to_response("template.html", {'state': my_state, 'country': my country })

The function above is nonsensical, but should not produce an error.

If you are defining country and state via some select tool on the web page, then

it will never work, as this is being evaluated BEFORE it goes to the users browser.

I’m not saying you can not get the form to work, just that this approach is wrong.

👤mtnpaul

0👍

When you use only 1 parameter, is my_App.views.country being used? Try reversing the order of the last 2 urls…

url(r'^my_index/(?P<country_id>\d+)/state/(?P<state_id>\d+)/$', 'my_App.views.state', name='state'),
url(r'^my_index/(?P<country_id>\d+)/state/$', 'my_App.views.country', name='country'),
👤Joseph Paetz

Leave a comment