How to pass an url as parameter of include
django, django-templates
Solution
I believe you would have to assign the url to a variable that is added to the context in order to use it in an include tag.
Example:
view:
from django.core.urlresolvers import reverse
def your_view(request):
url = reverse('the_url_name_to_reverse', args=[], kwargs={})
return render(request, 'the-template.html', {'url': url})
template:
{% include "button.html" with title="title" link=url %}
If it's a value you need in every template, you might consider adding a context processor to add the reversed url value to the context
Problem
I would like to know how I can pass url as parameter of an include in django template. I have in my code, a HTML file that is used to create a button. So when want to add this button I just include it. Problem is that 1 of the parameters is URL, and for now I have not found other solution than putting text url. SO what I have this: ``` {% include "button.html" with title="title" link="/new-event/" %} ``` and I would have to have something like: ``` {% include "button.html" with title="title" link={% url myview.view%} %} ``` Thank you very much!