To return redirect() with parameters with Python Django, we can call redirect
.
For instance, given that we have
url(r'element/update/(?P<pk>\d+)/$', 'element.views.element_update', name='element_update'),
in urls.py, we write
from django.shortcuts import redirect
from .models import Element
def element_info(request):
# ...
element = Element.object.get(pk=1)
return redirect('element_update', pk=element.id)
def element_update(request, pk)
# ...
in views.py to redirect to the view with name element_update
in the element_info
view.
The pk
argument is value of the pk
URL parameter.