Reputation: 51
How to post data with HttpResponseRedirect?
I have a button in Django admin change form:
<input type="submit" value="Test Peer" name="_peer-test">
and the view to get it:
def response_change(self, request, obj): ### response
if "_peer-test" in request.POST:
url = request.POST.get('obj', '/export')
return HttpResponseRedirect(url)
The first line def response_change(self, request, obj): has data
So if I type obj.name I will get the requested data.
What I want is to redirect to another view en post de information.
Upvotes: 1
Views: 3344
Reputation: 362
You can get your data from POST and send it as GET parametrs. See
def response_change(self, request, obj): ### response
if "_peer-test" in request.POST:
url = request.POST.get('obj', '/export')
if url != '/export':
# because "obj" in variable url
name = url.name
url += "?name={}".format(name)
return HttpResponseRedirect(url)
Thus you can get this value in view that need to recieve it. Example:
def reciever_view(request):
name = request.GET.get('name','')
# do some with name ...
Upvotes: 2