1

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

6
  • 3
    You should really use the url tag, but have you tried href="/jibambe_site_detail/{{ site.id }}"? Commented Jan 15, 2018 at 2:38
  • @schwobaseggl Yes I have. The result is just jibambe_site_detail/ Commented Jan 15, 2018 at 2:41
  • 2
    That would mean that either site is None or not in the context or does not have the attribute id. Commented Jan 15, 2018 at 2:43
  • 1
    @schwobaseggl from your comment that I should use url tag, I have been able to resolve the issue as follows <a href={% url 'site_details' pk=site.id %}>{{ site.name }}</a> Commented Jan 15, 2018 at 2:56
  • 1
    That looks much better! :-) Commented Jan 15, 2018 at 2:57

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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'),

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.