Django Drops Listview And Uses Detailview For A List Object, Then Gives Noreversematch
Solution 1:
Based from the errors, the absolute url doesn't match the definition for EntryDetail_url
. So to fix, change the url to properly use the correct kwarg for slug:
path('entry/<slug:slug>/', views.EntryDetail.as_view(), name='EntryDetail_url'),
And use the correct kwargs in get_absolute_url
to match the URL kwarg:
defget_absolute_url(self):
from django.urls import reverse
return reverse('EntryDetail_url', kwargs={'slug' : self.slug})
I am trying to call the index for this model’s objects, which is the same as a list. For reasons that I do not understand, and am tired of fighting with, it keeps trying to give me a single object on the detail template. The object 'executive-summary-hattie-urls-and-views' happens to be queryset[0].
It gives you the first object, but it fails when it tried to call its get_absolute_url
, because of first error caused by mismatch in URL kwargs. If you really want the model objects to call index (although it's not clear to me why), then you need to change get_absolute_url
of Entry
to point to the index:
defget_absolute_url(self):
from django.urls import reverse
return reverse('EntryIndex_url')
Solution 2:
Ok, I have most of this figured out. I bought a bootstrap theme from a designer, and in sprucing up my templates recently I foolishly followed some of his assumptions / suggestions. I also stuck get_absolute_url into the templates because I forgot, and was too lazy, to look up and use the proper url template tag. And I also forgot about the template work I had done when I started getting all these problems, because I thought it had to be 'code', not templates or design stuff. The fact that Django doesn't warn about template errors also didn't help. But, most of that has been fixed now, and the suggestions the two of you made were helpful. I am still still stuck on the admin link, so I am going to close this question and post a new, more targeted question about that one remaining issue. Thanks!
Post a Comment for "Django Drops Listview And Uses Detailview For A List Object, Then Gives Noreversematch"