私は非常に単純なブログを作成しましたが、いくつかのURLの問題に遭遇しています。タグと特定の投稿ビューについて、次の問題が発生します。
特定の投稿ビューの例
これら2つのサイトは同じレンダリングを行い、2番目のサイトは404をレンダリングします。website.com / post / 1 / hello
-world website.com/post/1/hello-world/non-sense(should
レンダリング404)
タグビュー
website.com/tag/python:これにより、pythonとタグ付けされたすべての投稿が表示されます。ただし...
website.com/tag/python/party:これにより、404をレンダリングする代わりに、「python/party」とタグ付けされたすべての投稿がレンダリングされます。
これが私のURLパターンの設定です。ご覧ください。
url(r'^post/(?P<pk>\d+)/(?P<post_title>)', DetailView.as_view(
model = post,
template_name = "post.html")),
url(r'^post/$', ListView.as_view(
queryset = post.objects.all().order_by("-date"),
template_name = "archives.html")),
url(r'^archives/$', ListView.as_view(
queryset = post.objects.all().order_by("-date"),
template_name = "archives.html")),
url(r'^tag/(?P<tag>[\w|\W]+)', 'tags'),
タグの更新され
たソリューション:
url(r'^tag/(?P<tag>[\w]+)\W*/$', 'tags'),
投稿の解決策:
url(r'^post/(?P<pk>\d+)/(?P<post_url>[\w-]+)/$', DetailView.as_view(
model = post,
template_name = "post.html")),
Huckleberry Finnとkrakaxにご協力いただき、ありがとうございます。