8π
β
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
π€Brandon Taylor
21π
Have you tried this syntax:
{% url 'some-url-name' arg arg2 as the_url %}
{% include "button.html" with title="title" link=the_url %}
π€rayed
- Programmatically add URL Patterns in Django?
- Celery does not registering tasks
- How to send django objects to celery tasks?
3π
Some might find this solution more suitable:
first create a filter
from django.core.urlresolvers import reverse
@register.filter()
def rev(value):
return reverse(value)
then use it in the template like this
{% include "button.html" with title="title" link="myview.view"|rev %}
π€omar
- Extend django Groups and Permissions
- When are threaded frameworks better than event-driven frameworks? (i.e., when is rails better than node.js?)
- How does Instagram use django?
- Email integration
Source:stackexchange.com