how to add href value in django view
<p>I am working on a project using django, in this i have a module which shows the listing of users in a table format, the data of users returns from django view to django template using ajax, so the action values with buttons also have to be returned from view to template in json response, as we usually do in bootstrap ajax datatables. </p>

<p>Now the problem is that i have to set href value in django view.</p>

<p><strong>Code in view is :-</strong> </p>

<pre><code>for user in users:
    actionValues='&lt;a title="Edit" class="btn btn-sm green margin-top-10" href="'"&gt;&lt;i class="fa fa-edit"&gt;&lt;/i&gt;&lt;/a&gt;
    &lt;a title="View" class="btn btn-sm blue margin-top-10" href="'"&gt;&lt;i class="fa fa-view"&gt;&lt;/i&gt;&lt;/a&gt;';
    inner_data_list = [
        i,
        user['first_name'],
        user['last_name'],
        user['email'], 
        user_type,
        '&lt;div id=%s class="bootstrap-switch  bootstrap-switch-%s  bootstrap-switch-wrapper bootstrap-switch-animate toogle_switch"&gt;&lt;div class="bootstrap-switch-container" &gt;&lt;span class="bootstrap-switch-handle-on bootstrap-switch-primary"&gt;&amp;nbsp;Active&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;label class="bootstrap-switch-label"&gt;&amp;nbsp;&lt;/label&gt;&lt;span class="bootstrap-switch-handle-off bootstrap-switch-default"&gt;&amp;nbsp;Inactive&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;'%(user['id'],checked),
       user['date_joined'],
       actionValues
    ]
    datalist.append(inner_data_list)
</code></pre>

<p>As you can see in code there is a variable actionValues it contains two buttons, related to each listing , Now what i have to do is i have to link these two buttons to function edit_details and view_details respectively. So how can i link these two buttons to their respective function in view.</p>

<p>Use <code>reverse()</code> function to get the url</p>

<p>If you have specified a url pattern name like</p>

<pre><code>url(r'^foo/bar/(?P&lt;user_id&gt;\d+)/$', some_viewfunc, name='some-view')
</code></pre>

<p><code>reverse('some-view', kwargs={'user_id': 100})</code> gives you <code>'/foo/bar/100/'</code></p>

<p>So use something like<br>
<code>'&lt;a href="%s"&gt;Link Name&lt;/a&gt;' % (reverse('some-view', kwargs={'user_id': 100}))</code></p>

python django