Reputation: 3779
I am reverse mapping a URL and getting an error. But I must be misunderstanding something, because what it says isn't right is precisely what I think I wanted to achieve (except the part about it not being right).
Here's the error message, to which I've added a couple newlines for readability here:
NoReverseMatch at /k/trip/search
Reverse for 'trip/save'
with arguments '()'
and keyword arguments
'{'when': '2015-02-01',
'from_city': 'nantes',
'to_city': 'paris'}'
not found. 1 pattern(s) tried:
['k/trip/save/?P<when>(\\d{4}-\\d{2}-\\d{2})/?P<from_city>([a-zA-Z ]+)/?P<to_city>([a-zA-Z ]+)/']
To be complete, the url.py line is this:
url(r'^save/?P<when>(\d{4}-\d{2}-\d{2})/?P<from_city>([a-zA-Z ]+)/?P<to_city>([a-zA-Z ]+)/',
kernel.views.TripSaveView.as_view(),
name='trip/save'),
and the reverse
line is this:
return redirect(reverse('trip/save',
kwargs={
'when': trip_form['departure_date'].value(),
'from_city': trip_form['from_city'].value(),
'to_city': trip_form['to_city'].value()}))
Upvotes: 0
Views: 64
Reputation: 31260
The name of the pattern must be inside the parens:
url(r'^save/(?P<when>\d{4}-\d{2}-\d{2})/(?P<from_city>[a-zA-Z ]+)/(?P<to_city>[a-zA-Z ]+)/',
kernel.views.TripSaveView.as_view(),
name='trip/save'),
Upvotes: 2