2

i create a create view in my blog app to create a post. in the create view I used the function get_success_url. I want when i create a post, that it will redirect to the blog_post_list. H

i get the error: NoReverseMatch

I guess it has to do sth with the urlpatterns.

main urls.py

    from django.conf.urls import url, include
    from django.contrib import admin

    from blog.views import AboutPageView, ContactPageView 

    urlpatterns = [
        url(r'', include('blog.urls', namespace='posts')),
        url(r'^blog/', include('blog.urls', namespace='posts')),
        url(r'^about/$', AboutPageView.as_view(), name='about'),
        url(r'^contact/$', ContactPageView.as_view(), name='contact'),


       #admin and login
       url(r'^admin/', admin.site.urls), 

    ]

urls in blog app

from django.conf.urls import url

from .views import blog_postListView, blog_postDetailView, blog_postCreateView 

urlpatterns = [
    url(r'^$', blog_postListView.as_view(), name='blog_post_list'),
    url(r'^create/', blog_postCreateView.as_view(), name='blog_post_create'),
    url(r'^(?P<slug>[-\w]+)$', blog_postDetailView.as_view(), name='detail'),
]

views in blogapp

class blog_postCreateView(CreateView):
    #model = blog_post
    form_class = blog_postForm
    template_name = "form.html"
    #fields = ["title", "content"]
    def get_success_url(self):
        return reverse("blog_post_list")
Sayse
  • 42,633
  • 14
  • 77
  • 146
Robert F.
  • 139
  • 2
  • 13

1 Answers1

2

You haven't included the namespace so it isn't able to find the blog_post_list

So just add the namespace in the reverse call

reverse("posts:blog_post_list")

For more information on NoReverseMatch errors, see What is a NoReverseMatch error, and how do I fix it?

Community
  • 1
  • 1
Sayse
  • 42,633
  • 14
  • 77
  • 146