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.
- [Answered ]-Vagrant – Django server – Why is host redirecting to https?
- [Answered ]-Django Checkbox checked / uncheck with rules
- [Answered ]-Django: Adding files to a form gives multiple argument error
- [Answered ]-Django static files (css) not working
Source:stackexchange.com