How To Pass Values From Html To Django Through URL
This can be done in three simple steps:
1) Add item id with
url
tag:{% for item in post %}
<tr>
<th>{{ item.id }}</th>
<td>{{ item.title }}</td>
<td>{{ item.body }}</td>
<td>
<a href={% url 'edit' id=item.id %}>Edit</a>
<a href={% url 'delete' id=item.id %}>Delete</a>
</td>
</tr>
{% endfor %}
2) Add path to urls.py:
path('edit\\/(?P<id>[0-9]+)$', views.edit, name='edit')path('delete
\\/(?P<id>[0-9]+)$', views.delete, name='delete')
3) Use the id on views.py:
def delete(request, id):
obj = post.objects.get(id=id)
obj.delete()
return redirect('dashboard')
Html Nunchi Django Application ki url lo value ni ele pass Chayali and Ele update chaye
Comments
Post a Comment