为什么这会返回 NoReverseMatch 错误?
看法:
def browse(request):
thing_list = Thing.objects.all()
if request.method == 'POST':
form = BrowseForm(request.POST)
if form.is_valid():
make = Make.objects.all()
return HttpResponseRedirect(reverse('browse_makes', args=[make]))
else:
form = BrowseForm()
return render(request, 'browse.html', {'form':form, 'thing_list':thing_list})
def makes(request, make):
ad_list = Thing.objects.filter(make=make)
return render(request, 'browse-makes.html', {'thing_list':thing_list})
网址:
url(r'^browse/$', 'axlepost.views.browse.browse', name='browse'),
url(r'^browse/(?P<make>[\w-]+)/$', 'axlepost.views.browse.makes', name='browse_makes'),
形式:
class BrowseForm(forms.Form):
make = forms.ModelChoiceField(queryset=Make.objects.all())
模型:
class Make(models.Model):
make = models.CharField(max_length=20)
class Thing(models.Model):
make = models.ForeignKey(Make)
返回Reverse for 'browse_makes' with arguments '([<Make: Samsung>],)' and keyword arguments '{}' not found.
感谢您对如何解决此错误的想法!