I am trying to work out how I would redirect to an HTML tab pane from a return redirect(...)
call. I thought this would work sort of like an HTML bookmark by adding the #id_target
to the link but even that does not work. The idea is that when one submits a new “volunteer hour” form, I want to take them back to the person detail page with the tab already selected.
I have an HTML page with “tabs” that have HTML bookmarks, as:
<div class"bs-example">
<ul id="myTab" class="nag nav-tabs" role="tablist">
<li class="nav-item">
<a href="#id_volunteer_hours_summary" class="nav-link" data-toggle="tab">Volunteer Hours Summary</a>
</li>
</ul>
</div>
...
<div class="tab-pane " id="id_volunteer_hours" role="tabpanel">
...
</div>
I tried the following in Django with no luck:
views.py:
def function(request, person_id):
code
...
return redirect('person_detail_volhrs', person_id)
urls.py:
urlpatterns = [
...
path(
"person/<person_id>#id_volunteer_hours",
views.person_detail,
name="person_detail_volhrs",
),
...
]
The #
gets translated to #
in the URL and I get an error about no matching URL.
Any tips or pointers (or blog posts even) would be greatly appreciated.