Hey,
Unsure how to phrase this but here’s my use case.
I’m making ajax calls based on some events in a table (row click/dbl-clicked). In order to avoid hard-coding URLs, I’m using a data-url attribute in my templates, like so:
<tbody id="details" data-url="{% url 'pickings:details' %}">
For instance in this case, the body of the table is initially empty. When I want to make an ajax query to populate it, jquery fetches the data-url attr of the #details element and appends to it the html rendered by the server. Works well.
However, there are instances where the reverse URL expects say an int:pk, like so:
<table class="table table-bordered" id="table_list" width="100%" cellspacing="0" data-url="{% url 'pickings:detail_product' %}">
With the corresponding urls.py:
path('product/<int:pk>/', views.PickWarehouseDetailedView.as_view(), {"section": "product"}, name='detail_product', ),
Obviously, when rendering my template, django complains that it cannot find a reverse for
data-url="{% url ‘pickings:detail_product’ %}", since I don’t know which one it will be at that time.
My current workaround is to provide a dummy one & strip it when I make the ajax call (e.g. a row has been double-clicked, and there’s an associated product pk). However I would ideally like to:
- Keep using the reserve URL the way I do to tell my jquery requests where to go
- avoid messing around with stripping strings from URL
- so more or less “silence” the Django error about not finding a reverse%