I am trying to render dynamic Url in Django template as follows
<a href={{'jibambe_site_detail/'|add: site.id}}>{{ site }}</a>. This however is returning a TemplateSyntaxError at /jibambe_sites/
add requires 2 arguments, 1 provided. What am I missing or how should I render this dynamic URL, I want it to produce something like jibambe_site_detail/1
2 Answers
OP's strategy changed on this one but OP's original error seems to be because of the space after colon.
Use add:site.id instead of add: site.id
See a similar question about default here
Comments
From @schwobaseggl comment, I was able to add a dynamic url variable as follows <a href={% url 'site_details' pk=site.id %}>{{ site.name }}</a>
then in the urls.py urlpatterns, I gave the path to jibambe_site_details a name path('jibambe_site_detail/<slug:pk>', JibambeSitesDetails.as_view(), name='site_details'),
urltag, but have you triedhref="/jibambe_site_detail/{{ site.id }}"?jibambe_site_detail/siteis None or not in the context or does not have the attributeid.urltag, I have been able to resolve the issue as follows<a href={% url 'site_details' pk=site.id %}>{{ site.name }}</a>