Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django redirect() with additional parameters

Why is it that when I try to pass additional parameters, I get the error:

The below works fine! (Without parameters)

def first(request):
    return redirect('confirm')

def confirm(request):
    return render(request, 'template.html')

However this is what I need, which doesn't work as expected, and I get the error:

Reverse for 'confirm' with keyword arguments '{'email': 'email'}' not found. 1 pattern(s) tried: ['book/booking_confirmation/$']

def first(request):
    return redirect('confirm', email='some_email')

def confirm(request, email):
    return render(request, 'template.html', { 'email': email} )

urls.py

urlpatterns += [
    url(r'^booking_confirmation/$', views.confirm, name='confirm'),
]
like image 876
GRS Avatar asked Aug 23 '26 22:08

GRS


1 Answers

If you don't want to pass the email via the URL in the redirect, it may be easiest to store it in the session.

def first(request):
    request.session['email'] = 'some_email'
    return redirect('confirm')

def confirm(request):
    return render(request, 'template.html', {'email': request.session['email']})
like image 173
Will Keeling Avatar answered Aug 25 '26 12:08

Will Keeling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!