[Answered ]-The requested URL was not found on this server. Django

2👍

Your single_post regex catches all urls started with ‘post/’. Place this url at the end of the patterns:

urlpatterns = patterns('',
    url(r'^tag/(?P<slug>\S+)/$', TagView.as_view(),
                                    name='tagger'),
    url(r'^post/add_comment/(?P<slug>\S+)/$',
        'blog.views.add_comment', name="commenter"),
    url(r'^$', PostsList.as_view(), name="all_posts"),
    url(r'^post/(?P<slug>\S+)/$', SinglePost.as_view(),
                                    name='single_post'),
)

Or, as a more correct solution, change the \S+ regex to valid slug regex [\w-]+:

urlpatterns = patterns('',
    url(r'^post/(?P<slug>[\w-]+)/$', SinglePost.as_view(),
                                    name='single_post'),
    url(r'^tag/(?P<slug>[\w-]+)/$', TagView.as_view(),
                                    name='tagger'),
    url(r'^post/add_comment/(?P<slug>[\w-]+)/$',
        'blog.views.add_comment', name="commenter"),
    url(r'^$', PostsList.as_view(), name="all_posts"),
)

0👍

You have two regular expressions which are overlapping:

url(r'^post/(?P<slug>\S+)/$', SinglePost.as_view(),
                                name='single_post'),
[...]
url(r'^post/add_comment/(?P<slug>\S+)/$',

You should change the first one to be less greedy, for example: r'^post/(?P<slug>[^/]+)/$' or place it at the end.

Leave a comment