Question

So i am trying to pass a variable from one view to another, after a successful POST form submission, using reverse, thus:

url = "%s?model_class=Attributes" % reverse('Directories:edit_models')
return HttpResponseRedirect(url)

model_class is not a form field but a simple variable I created inside my view. After redirection the url is displayed correctly, as specified in my url variable (.../?model_class=Attributes). As a result, in the second view I now try to access the variable using the following code:

mvar = request.POST.get('model_class')

but when I try to render mvar in my template or print it, it says model_class is not defined.

Is my code wrong or should i change my approach of passing parameters between views?

Was it helpful?

Solution

You should use mvar = request.GET.get('model_class'). As far as I know on redirect you'll retrieve new url via GET request, not POST.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top