2👍
✅
You are handing reverse()
a QuerySet rather than 1 value. Also its an .all()
query so it may well have multiple objects and it’s not related to the form result.
make = Make.objects.all() # QuerySet = ([<Make: Samsung>], [<Make: Sony>], [<Make: Apple>], etc)
return HttpResponseRedirect(reverse('browse_makes', args=[make])) # Expects 1 value
Assuming you want to redirect to the Make
selected in the form then you’ll need something like:
if form.is_valid():
# Get the valid form data
cd = form.cleaned_data
# Get the selected Make
make = cd.get('make')
# Redirect - note 'make.make'. You want to pass the value not the object
return HttpResponseRedirect(reverse('browse_makes', kwargs={'make': make.make}))
0👍
I think there are couple of issues
- Your urls does not correspond to appropriate view
change this line
url(r'^browse/(?P<make>[\w-]+)/$', 'axlepost.views.browse.makes', name='browse_makes'),
to
url(r'^browse/(?P<make>[\w-]+)/$', 'axlepost.views.browse', name='browse_makes'),
-
Change your view definition to take
make
parameterdef browse(request, make):
…
#change your local variable ‘make’ to something else
Source:stackexchange.com