Django URL error: noreversematch in my app

I'm seeing this error in my Django app

NoReverseMatch at /kaitorihyou/delete_fields_group/18

Reverse for 'delete_fields_group' with arguments '('',)' not found. 1 pattern(s) tried: ['kaitorihyou/delete_fields_group/(?P<fields_group_id>[0-9]+)\\Z']

This is the line in my template that is redirecting to this URL

<form action="{% url 'kaitorihyou:delete_fields_group' fields_group_id %}" method="delete">

My urls.py does contain this pattern in questiion

app_name = "kaitorihyou"
urlpatterns = [
    path('delete_fields_group/<int:fields_group_id>', views.delete_fields_group, name="delete_fields_group"),
    # etc.
]

Why is the url pattern not matching?

If I change the action= in my form to this it works

<form action="/kaitorihyou/delete_fields_group/{{ fields_group_id }}" method="delete">

Found the answer myself.

The problem was that urls.py didn't contain a trailing slash, so

# this is wrong
path('delete_fields_group/<int:fields_group_id>', ...),

# should be this
path('delete_fields_group/<int:fields_group_id>/', ...),
Back to Top