I am passing a variable in django template named "link". This is my code snippet in views.py
link = "msdetail/{{item.post_id}}"
return render(request, "mart/all-products.html", {'t': ms, 'cat':category, 'link':link})
and on html file :
<a href={% url '{{link}}' %} class="btn btn-primary">View</a>
it is giving this error:
"NoReverseMatch at /mart/menshirt Reverse for '{{link}}' not found. '{{link}}' is not a valid view function or pattern name.".....
the error happens when i click the button. Can I not pass url like this or is it some other issue?
<a href='{{link}}' class="btn btn-primary">View</a>
Typing {% url 'X' %}
is saying, Get me the URL
which has name='X'
.
This is not the case, Your case has a variable that you want to include it in the context, That's all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.