teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

修正

2020/06/03 03:40

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -4,4 +4,7 @@
4
4
  posts = Post.objects.filter(categories__in=[category])
5
5
  context = {"category": category, "posts": posts}
6
6
  return render(request, "blog_category.html", context)
7
+ ```urls↓
8
+ ```Python
9
+ path("<slug:category>/", views.blog_category, name="blog_category"),
7
10
  ```

2

修正

2020/06/03 03:40

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -1,4 +1,4 @@
1
- BlogCategoryはManyToManyFieldでつないでいますよね。だったら、
1
+ BlogCategoryはManyToManyFieldでつないでいますよね。だったら、
2
2
  ```Python
3
3
  def blog_category(request, category):
4
4
  posts = Post.objects.filter(categories__in=[category])

1

修正

2020/06/03 00:05

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -1,7 +1,7 @@
1
1
  BlogはCategoryはManyToManyFieldでつないでいますよね。だったら、
2
2
  ```Python
3
3
  def blog_category(request, category):
4
- posts = Post.objects.filter(categories__in=category)
4
+ posts = Post.objects.filter(categories__in=[category])
5
5
  context = {"category": category, "posts": posts}
6
6
  return render(request, "blog_category.html", context)
7
7
  ```