So I have a form in Django that lets users write their diary.
Now I want to add edit button and delete button, but I'm having error. So here are the codes.
template (detail.html)
...
<form method='post' class="form-group">
{% csrf_token %}
<div class="row justify-content-center">
<a href="{% url 'delete' authuser_id slug %}">
<button class='btn btn-primary button-delete'>Delete</button>
</a>
</div>
</form>
urls.py
...
urlpatterns = [
...
path('detail/<int:authuser_id>/<slug:slug>', views.detail, name='detail'),
path('detail/<int:authuser_id>/<slug:slug>', views.delete, name='delete'),
]
views.py
from .models import DiaryInput
...
def detail(request, authuser_id, slug):
todayDiary = DiaryInput.objects.get(slug=slug)
return render(request, '/detail.html', {'todayDiary' : todayDiary})
def delete(request, authuser_id, slug):
todayDiary = DiaryInput.objects.get(slug=slug)
todayDiary.delete()
return redirect('/')
When I go to the detail page of a specific diary, I get an error that says :
Reverse for 'delete' with arguments '('',)' not found. 1 pattern(s) tried: ['detail/detail/(?P[0-9]+)/(?P[-a-zA-Z0-9_]+)/delete$']
I believe there is something wrong with my template, in the {% url %} tag, but I don't see what I've done wrong. I appreciate your help :)