I have a page that needs a POST id parameter to show routine information
In that page i have a form that posts data to update routine information, the form url is:
When i access the first page the information is shown correctly.
When i post to second form, view code is executed but i end my view code with a render of the first page:
return render(request, 'rxWod/edit_routine.html', context)
The page is shown correctly with the updated data but the url remains the second one.
I need to return to /edit_routine/ URL, remember that /edit_routine/ needs the POST field, so a simple redirect doesnt work.
My url configuration is:
path('edit_routine/', views.edit_routine, name='edit_routine'),
path('exchange_routine_exercise/', views.exchange_routine_exercise, name='exchange_routine_exercise'),
One solution could be using AJAX calls from edit_routine instead of using forms, but i dont know if there is a better or simple way of doing it.
Thanks in advance.
I can think of at least four ways of doing this - but it kinda depends upon why you need the URL changed.
If it’s just because your form in
edit_routine needs to submit to
edit_routine, you could set the
action attribute on the
submit button to make the form submit to
edit_routine regardless of which URL rendered that form.
You could pass the necessary parameter as a query parameter in the url. (e.g.
You could stash the current id in the user’s session to be accessed by the view handling
Thank you very much for your response, i am new in web programming world and i am reading about each option, i have a lot of to learn.
My first think is that the 3 option is the most appropiate for me.
Thank you for your sugestions.