DEV Community

kawuondo
kawuondo

Posted on

Answer: Django doesn't match CreateView if the route begins with 'post/'

Django will use the first matching regex, which in this case is r'^post/(?P<slug>[-\w]+)/$'. This routes to PostDetailView with a slug of new. Since you don't have a post with that slug, the view will raise a 404.

To fix this, simply put the CreatePostView above the PostDetailView:

Top comments (0)