2

I'm wondering on how I can access a UpdateView by using a uuid as slug. So my goal is an URL like

http://myapp.example.de/edit/7efdbb03-bdcf-4b8a-85dd-eb96ac9954fd

I have defined the the view like this:

class DeviceEventUploadView(UpdateView):

    model = Event
    slug_url_kwarg = 'uuid_slug'
    slug_field = 'unique_id' 

and urls.py like this:


urlpatterns = [
    path('admin/', admin.site.urls),
    path('edit/<uuid:uuid_slug>',
        DeviceEventUploadView.as_view(),
        name='event_update'),
]

Here I'm getting:


Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:

    admin/
    ^edit/<uuid:uuid_slug> [name='event_update']

The current path, edit/7efdbb03-bdcf-4b8a-85dd-eb96ac9954fd/, didn’t match any of these.

Where is my failure in thinking?

frlan
  • 6,950
  • 3
  • 31
  • 72
  • 2
    You forgot to close the ``. It needs a closing angle bracket `>`. Furthermore this is `path` syntax. – Willem Van Onsem Nov 07 '21 at 15:49
  • Good catch. I've changed this and still not working (updating my question) – frlan Nov 07 '21 at 15:57
  • @frian: based on the error message, you still use `url`, not `path: a path converts it to a regex internally, and that will be specified in the error message. – Willem Van Onsem Nov 07 '21 at 16:01
  • 2
    @WillemVanOnsem Hmmm. I think I've found that issue now. The ending / was still present in the URL while testing. Without it seems to work. Stay tuned ;) – frlan Nov 07 '21 at 16:10
  • 1
    @frian: ah yes, normally paths should end with a slash, there is a Django setting named `APPEND_SLASH` that if true will look for the url first, then append a slash if it does not end with a slash, and try to look for the URL again. – Willem Van Onsem Nov 07 '21 at 16:16
  • 1
    i think the title should say "slug" and not "slag" lol – user1849962 Nov 07 '21 at 20:47

1 Answers1

2

You forgot to close the <uuid:uuid_slug>. It needs a closing angle bracket >. Furthermore this is path syntax. You thus define this with:

path(
    'edit/<uuid:uuid_slug>/',
    DeviceEventUploadView.as_view(),
    name='event_update'
),
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555