[英]django reverse URL not matching
I am reverse mapping a URL and getting an error. 我反向映射URL并出现错误。 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.py行是这样的:
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: reverse
线是这样的:
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'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.