NoReverseMatch in / posts / when using an absolute url in django

In my model.py, I defined a class:

def get_absolute_url(self): return reverse("posts:detail", kwargs={"id":self.id}) 

In url.py (Project url)

  urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^posts/', include("posts.urls", namespace='posts')), ] 

In url.py (app url)

  urlpatterns = [ url(r'^$', post_list), url(r'^create/$', post_create), url(r'^(?P<id>\d+)/$', post_detail, name='detail'), url(r'^update/$', post_update), url(r'^delete/$', post_delete), ] 

In index.html

 {% for obj in object_list %} {% url "posts:detail" id=obj.id %} <a href='{{ obj.get_absolute_url }}'>{{ obj.title }}</a><br/> {{ obj.content }}<br/> {{ obj.timestamp }}<br/> {{ obj.updated_date }}<br/> {{ obj.id }}<br/> {% endfor %} 

During reboot, it gives

 Reverse for 'detail' with arguments '()' and keyword arguments '{'id': 1}' not found. 0 pattern(s) tried: [] 
+6
source share
1 answer

The code for calling URLpatterns and reverse looks good and works fine for me. I would check that the view function has an id argument and that you are not loading the cached result. It could also be due to old pyc downloads, try deleting them as suggested by @knbk.

0
source

All Articles