[Django]-On my Blog – matching query does not exists

3πŸ‘

βœ…

For your 'create_post' path, the <slug:slug> will first capture this, since createcontent is a valid slug as well. Therefore you should alter the urlpatterns. You can swap the two:

urlpatterns = [
    path('content/createcontent/', views.create_post, name='create_post'),
    path('content/<slug:slug>/', views.post_detail, name='post_detail'),
]

so now createcontent will be matched first, but still this is not a good solution, since now if your article has as slug createcontent, you can not display it. Likely it is better to make non-overlapping paths. For example:

urlpatterns = [
    path('content/createcontent/', views.create_post, name='create_post'),
    path('post/<slug:slug>/', views.post_detail, name='post_detail'),
]

here regardless what the value for slug is, it will never overlap with the content/createcontent path.

You of course still need to finish the view itself, since right now, it will not handle a POST request properly.

Leave a comment