4
我正在使用Django 1.5并尝试将args传递给我的URL。当我使用前两个参数时,下面的代码工作正常,第三个参数出现错误。我已经提到了用于url
用法的新Django 1.5更新,并相应地使用了URL名称的引号。NoReverseMatch:带参数'()'和关键字参数
NoReverseMatch: Reverse for 'add_trip' with arguments '()' and keyword arguments '{u'city': 537, u'score': 537, u'time': 35703, u'distance': 1196.61}' not found
urls.py
url(
r'^add/(?P<city>\w+)/(?P<score>\w+)/(?P<distance>\w+)/(?P<time>\w+)$',
'trips.views.add_trip',
name='add_trip'
),
HTML文件
<a href="{% url "add_trip" city=data.city score=data.score distance=data.distance time=data.time%}">Add/delete</a>
如果我只使用有两个参数(即城市和分数,然后正常工作),否则我得到没有反向匹配错误。
views.py
def SearchTrips(request):
city = request.POST['city'].replace(" ","%20")
location = request.POST['location'].replace(" ","%20")
duration = request.POST['duration']
#url = "http://blankket-mk8te7kbzv.elasticbeanstalk.com/getroutes?city=%s&location=%s&duration=%s" % (city, location, duration)
url= "http://blankket-mk8te7kbzv.elasticbeanstalk.com/getroutes?city=New%20York%20City&location=Park%20Avenue&duration=10"
print url
try:
resp = urllib2.urlopen(url)
except:
resp = None
if resp:
datas = json.load(resp)
else:
datas = None
return render(request, 'searchtrips.html', {'datas': datas})
你能发表你的看法吗? –
我认为regx存在一些问题,如果我将“分数”传递给所有参数,那么我不会收到此错误。 – Mayank
我想'data.time'不符合'\ w +'格式。仔细检查一下。 –