2๐
โ
So, presumably your url.py looks something like:
urlpatterns = patterns(
'',
# Patterns:
url(r'^(?P<username>[\w-]+)/(?P<createdby>[\w-]+)/$', transaction, name="transaction"),
....
Your view is:
def transaction(request, username, createdby):
...
Then your template fragment is:
<a href="{% url transaction item.sender item.receiver %}">{{ item.sender }}</a>
Or you could define the following in your Transaction
class (the urls.py file must remain):
def get_absolute_url(self):
from django.core.urlresolvers import reverse
return reverse('transaction', kwargs={'username': self.sender, 'createdby': self.receiver})
And then your template would look like:
<a href="{{ item.get_absolute_url }}">{{ item.sender }}</a>
But geez, this is all Django 101.
๐คElf Sternberg
Source:stackexchange.com