NoReverseMatch at /assetAdmin/ error in Django

I have created a table that contains details about all the Assets. I wish to update the details of the asset. So, from the table, a made asset_id as URL to update page as happens in Django Administration. But after I added the URL pattern to update the asset, I am receiving this error:

Reverse for 'asset-update' with keyword arguments '{'id': UUID('cd7edefa-796d-428e-bcec-c90ceecc7fc3')}' not found. 2 pattern(s) tried: ['assets/(?P<pk>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/update/\\Z', 'assets/(?P<pk>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/\\Z']

Here is my urlpatterns from urls.py:

urlpatterns = [
    path('home/', home, name='home'),
    path('assets/', assets, name='assets'),
    path('assetAdmin/', adminAssetView, name='assetsAdmin'),
    path('createAsset/', createAssetView, name='createAssets'),
    path('assets/<uuid:pk>/update/', assetUpdateView.as_view(), name='asset-update'),
    path('register/', register, name='register'),
    path('login/', auth_views.LoginView.as_view(template_name='assets/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(template_name='assets/logout.html'), name='logout'),
    path('accounts/profile/', profile, name='profile'),
    path('admin/', admin.site.urls),
]

Here are the views involved:


@user_passes_test(lambda u: u.is_superuser)
def adminAssetView(request):
    context = {
        'assets': asset.objects.all(),
        'users':User.objects.all(),
    }
    return render(request, 'assets/assetAdmin.html', context)

class assetUpdateView(SuperUserCheck, LoginRequiredMixin, UserPassesTestMixin, UpdateView):
    model = asset
    fields = ['currentOwner',]

    def form_valid(self, form):
        return super().form_valid(form)
    
    def test_func(self):
        asset = self.get_object()
        if self.request.user.is_superuser == True:
            return True
        return False

And here is the part in assetAdmin.html where I am using asset-update urlpattern

{% for asset in assets %}
<tr>
  <td><a href="{% url 'asset-update' id=asset.id%}">{{ asset.id }}</a></td>
  <td>{{ asset.asset_type }}</td>
  <td>{{ asset.asset_name }}</td>
  <td>{{ asset.brand }}</td>
  <td>{{ asset.isActive }}</td>
  <td>{{ asset.currentOwner }}</td>
</tr>
{% endfor %}

Please let me know where am I wrong? Any kind of help or suggestions will be highly appreciated.

    {% for asset in assets %}
     <tr>
     <td><a href="{% url 'asset-update' pk=asset.id%}">{{ asset.id }}</a></td>
     <td>{{ asset.asset_type }}</td>
    <td>{{ asset.asset_name }}</td>
    <td>{{ asset.brand }}</td>
     <td>{{ asset.isActive }}</td>
    <td>{{ asset.currentOwner }}</td>
     </tr>
    {% endfor %}

change id to pk in your template

Back to Top