forms - DJANGO Generic Views: How to use reverse() in get_absolute_url method? -


i'm trying implement generic editing views shown here:

i started createview renders , submits data correctly. however, getting error when tries use reverse() return detail view page new object.

here error message:

noreversematch @ /work/clients/create/ reverse 'clientdetailview' arguments '('14',)' , keyword arguments '{}' not found. 0 pattern(s) tried: []

here how defined get_absolute_url() in model:

def get_absolute_url(self):     return reverse('clientdetailview', kwargs={'pk': self.pk}) 

my view called clientdetailview. i'm not sure other information helpful.

here class clientdetailview:

class clientdetailview(generic.detailview):         model = client     template_name = 'work/client_detail.html'` 

and here url() urls.py:

url(r'^clients/(?p<pk>[0-9]+)/$', views.clientdetailview.as_view(), name='clients_detail'),` 

can explain doing wrong?

i solved own problem. had add namespace reverse() method:

return reverse('work:clients_detail', kwargs={'pk': self.pk}) 

i appreciate if else explain why needed this.

here complete urls.py: django.conf.urls import url

from . import views  app_name = 'work' urlpatterns = [     url(r'^work_orders/$', views.workordersindexview.as_view(), name='quotes_index'),     url(r'^work_orders/(?p<pk>[0-9]+)/$', views.workordersdetailview.as_view(), name='work_orders_detail'),     url(r'^quotes/$', views.quotesindexview.as_view(), name='quotes_index'),     url(r'^quotes/(?p<pk>[0-9]+)/$', views.quotesdetailview.as_view(), name='quotes_detail'),     url(r'^project/(?p<pk>[0-9]+)/$', views.projectdetailview.as_view(), name='project_detail'),     url(r'^project/create/$', views.projectcreateview.as_view(), name='project_create'),     url(r'^project/(?p<pk>[0-9]+)/update/$', views.projectupdateview.as_view(), name='project_update'),     url(r'^project/(?p<pk>[0-9]+)/delete/$', views.projectdeleteview.as_view(), name='project_delete'),     url(r'^clients/$', views.clientview.as_view(), name='client_index'),     url(r'^clients/(?p<pk>[0-9]+)/$', views.clientdetailview.as_view(), name='clients_detail'),     url(r'^clients/create/$', views.clientcreateview.as_view(), name='client_create'),     url(r'^clients/(?p<pk>[0-9]+)/update/$', views.clientupdateview.as_view(), name='clients_update'),     url(r'^clients/(?p<pk>[0-9]+)/delete/$', views.clientdeleteview.as_view(), name='clients_delete'),   ] 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -