How to transfer edit method of an ID to a button/links in Django?
<p>This is the code in my ulrs.py</p>

<pre><code>url(r'^viewguides/detail/(?P&lt;id&gt;\d+)/edit/$', views.post_update, name='update'),
</code></pre>

<p>Now I want to make it look like this:</p>

<pre><code>&lt;a href="/detail/(?P&lt;id&gt;\d+)/edit" class="btn btn-default btn-lg" style="background-color: transparent;"&gt;&lt;font color="Orange"&gt; EDIT &lt;/font&gt;&lt;/a&gt;&lt;hr&gt;
</code></pre>

<p>So that I can edit the certain ID that I want to. But it gives me an error. How do you do it? or is there any other way? I'm new to Django.</p>

<p>I just asked my colleagues who have some experience in Django. The answer is very simple.</p>

<p>you just need to create this function in "models.py" :</p>

<pre><code>def get_absolute_url(self):
    return "/viewguides/detail/%s/" %(self.id)
</code></pre>

<p>and then you can call it in the html by:</p>

<pre><code>&lt;a href="{{obj.get_absolute_url}}edit" class="btn"&gt;EDIT&lt;/a&gt;
</code></pre>

<p>Every time you click the btn EDIT, it will take you to the following edit page with the given id (id that contains the forms/models of the user).</p>

python django python-2.7 django-templates django-views