Im new to django and was struck by using slug, now Im confused how to use the ID parameter and convert to slug
URL.py
If you want to use both slug and id, your URL pattern should look like this:
url(r'^deletePost/(?P[\w-]+)-(?P[0-9]+)/$',
views.delete_post, name='delete_post')
And your view should look like this:
def delete_post(request, **kwargs):
# Here kwargs value is {'slug': 'qw', 'id': '1'}
posts = Post.objects.get(**kwargs)
if request.method == 'POST':
posts.delete()
return redirect('home')
# ... (I guess this view does not end here)
And your template also have to set both: