[Django]-Link with parameter in Django templates

7👍

One way of doin it:

<a href="/member/profile/edit/code={{ sal.id }}"> Edit</a>

But a preferred method is to use a URL tag.

{% url edit_profile sal.id %}

where, in your urls.py you have an entry with name edit_profile

You can also, if you want, reverse the URLs in the model in a method, say get_absolute_url and call that method, like:

{{sal.get_absolute_url}}

where, the said method is defined as follows:

@models.permalink
def get_absolute_url(self):
    return ['edit_profile',(self.id,)]
👤lprsd

Leave a comment