我想知道如何通過使用 uuid 作為 slug 來訪問 UpdateView。所以我的目標是一個像
http://myapp.example.de/edit/7efdbb03-bdcf-4b8a-85dd-eb96ac9954fd
我已經定義了這樣的視圖:
class DeviceEventUploadView(UpdateView):
model = Event
slug_url_kwarg = 'uuid_slug'
slug_field = 'unique_id'
和 urls.py 像這樣:
urlpatterns = [
path('admin/', admin.site.urls),
path('edit/<uuid:uuid_slug>',
DeviceEventUploadView.as_view(),
name='event_update'),
]
在這里我得到:
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.
我的思維失敗在哪里?
uj5u.com熱心網友回復:
你忘記關閉<uuid:uuid_slug>. 它需要一個右尖括號>。此外,這是path語法。因此,您可以通過以下方式定義:
path(
'edit/<uuid:uuid_slug>/',
DeviceEventUploadView.as_view(),
name='event_update'
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/352973.html
上一篇:first_name被添加到元組
下一篇:如何在DRF中對串列進行排序?
