Reverse for '' with no arguments not found. 1 pattern(s) tried: .../.../(?P<slug>[-a-zA-Z0-9_]+)$']

I’m trying to use a Class Based view with DetailView.

But I get the following error:
Reverse for ‘prijzenupdaten’ with no arguments not found. 1 pattern(s) tried: [‘dashboardadmin/prijzenupdaten/(?P[-a-zA-Z0-9_]+)$’]

These are some lines of my code:
URLS:

from django.urls import path
from . import views

urlpatterns = [
    path('login', views.loginPageView.as_view(), name="loginpage"),
    path('admin', views.admin, name="adminpage"),
    path('dashboardadmin', views.dashboardadmin, name="dashboardadmin"),
    path('dashboardadmin/klantaanmaken', views.klantaanmaken, name="klantaanmaken"),
    path('dashboardadmin/algemeenoverzicht', views.algemeenOverzichtView.as_view(), name="algemeenoverzicht"),

    path('dashboardadmin/prijzenupdaten/<slug:slug>', views.prijzenUpdatenView.as_view(), name="prijzenupdaten"),

    path('dashboardadmin/leveringeninvoegen', views.leveringeninvoegen, name="leveringeninvoegen"),
    path('dashboardadmin/ophalingeninvoegen', views.ophalingeninvoegen, name="ophalingeninvoegen"),
    path('dashboardadmin/wegingeninvoegen', views.wegingeninvoegen, name="wegingeninvoegen"),
    path('dashboardklant', views.dashboardklant, name="dashboardklant"),
]

VIEWS:

from django.views.generic.base import TemplateView
from webapp.forms import loginForm
from webapp.models import Account, Service, Prijzen
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect, render
from django.contrib.auth.forms import UserCreationForm
from django.contrib import messages
from django.contrib.auth.hashers import make_password
from django.views.generic.edit  import CreateView, FormView
from django.views.generic.list import ListView
from django.views.generic import DetailView


from django.contrib.auth import authenticate, login, logout

# Create your views here.

from django.shortcuts import render
class prijzenUpdatenView(DetailView):
    model = Prijzen
    template_name = 'webapp/prijzenupdaten.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['service'] = Prijzen.objects.all()
        return context

The database is also correctly filled:

What am I doing wrong?

Somewhere, either in a view or a template, you’re trying to do a reverse lookup on the url named “prijzenupdaten” without supplying the required parameter (the slug field).

This could be happening either from calling reverse in a view or using the url tag in a template.

Since you didn’t post either the complete traceback or any of the templates / views that might be making a reference to that url, I can’t be more specific than this.

Yes I am in fact using a URL tag in my dashboardadmin template. Are you saying I can’t use this anymore when I am trying to reference to a DetailView template?

Picture:

Okay so I found a solution for it by doing this:

This is the page that needs a reference to ‘prijzenupdaten’ page. Since I could not use object.slug, I’m hardcoding the name of the slug. Is there a better way to go about this?

Why can you not use object.slug?

Side note: Please do not post images of code or templates, copy and paste the text into the message.

1 Like

It cannot find the value of object.slug in dashboardadmin, but I can use it in ‘prijzenupdaten’. My dashboardadmin page isn’t a DetailView generated template.

I’m going to need more details than this.

Why not? What data are you passing from your view into your context? (It might be helpful if you posted that view.) How does dashboardadmin know which object to link to?

This doesn’t really matter. It’s a question of what data does the view provide to the template.