[Fixed]-Django reverse not working with arguments

1👍

What you are expecting inside your view is a GET parameter from query string. Something your expected URL should be something like,

www.example.com/vendor/?vendor_id=12345

And below,

return HttpResponseRedirect(reverse('vendor_data', kwargs={'vendor_id':vendor_id}))

will redirect you to something like,

www.example.com/vendor/12345

For which your view should expect an additional parameter vendor_id,

def vendorData(request, vendor_id):

and accordingly your rest of the code might change.

Solution to your problem:

return HttpResponseRedirect("{}?vendor_id={}".format(reverse('vendor_data'), vendor_id))

Leave a comment