Reputation: 53
I need to get data from a redirect, but I can't really figure out how. The method is GET as I can see from my print. But I have tried everything I found on searching for this without luck. What am I doing wrong? I really appreciate any help.
I have this redirect:
return redirect('/list-view', new = 'new')
My urls looks like this:
path('list-view/<new>', views.list_view, name='list'),
Then my list-view is:
def list_view(request, *args, **kwargs):
print(request.method)
if request.method == 'GET':
aa=request.GET.get('new')
if aa:
bb = (request.GET.get('new'))
print (bb['new'])
Upvotes: 0
Views: 274
Reputation: 5270
If you define a parameter in the url, like you are doing, you can actually put it as a input on the view function,
def list_view(request, new):
# ...
BTW to use the name you need to reverse it, something like this,
new = True
return HttpResponseRedirect(reverse('list', args=(new,)))
Upvotes: 1
Reputation: 91
Use the name of the URL instead of the absolute path. return redirect('list', new = 'new')
Upvotes: 0