简体   繁体   中英

django reverse URL not matching

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()}))

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'),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM