In the example below, I'm trying to use the URL pattern name (ie, 'update_profile') instead of the absolute path (/profile/str:pk/update) in one of my views. This way if I later change my url path, I don't have to go an change each time I used the absolute path.
My question: how do I pass 'pk' into a pattern name? I've tried things like:
success_url = 'update_profile' % (pk)
But that doesn't seem to work.
urls.py
path('/profile/<str:pk>/update', views.ProfileUpdateView.as_view(), name='update_profile'),
views.py
def submit_profile_form(request, pk):
if request.method == "POST":
success_url = 'update_profile' // <------ How do I pass 'pk' in here?
...
return redirect(success_url)
Thanks for your help!