Django: Generic detail view must be called with either an object pk or a slug

You need to pass an object identifier (pk or slug) so your views know which object they’re operating on.

Just to take an example from your urls.py:

url(r'^facture/ajouter/$', Facture_Creer.as_view(), name="facture_creer"),
url(r'^facture/modifier/(?P<pk>\d+)/$', Facture_Update.as_view(), name="facture_update"),

See how the second one has (?P<pk>\d+)/? That is passing a pk to the UpdateView so it knows which object to use. Thus if you go to facture/modifier/5/, then the UpdateView will modify object with pk of 5.

If you don’t want to pass a pk or slug in your url, you’ll need to override the get_object() method and get your object another way. Url here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)