Reputation: 110163
I have the following url in my template:
<a href="{% url titles order_item.title.id order_item.id 'assets' %}
?expanded=chaptering">Link
</a>
However, what I need to do is build the url in my model, so I can do something like this in my template:
{{ task.get_task_url }}
How would I get {% url titles order_item.title.id order_item.id 'assets' %}
(for example, "/tasks/2/4/") in a model?
Can I use redirect
and capture the url value or something?
Upvotes: 0
Views: 61
Reputation: 37319
This is what the reverse
function does.
https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse
from django.core.urlresolvers import reverse
def get_task_url(order_item):
return reverse('titles', args=(order_item.title.id, order_item.id, 'assets'))
Or kwargs, as appropriate.
Upvotes: 2