-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create views for Blog index, categories and post details
- Loading branch information
1 parent
c23d5ec
commit e29f5c6
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
from django.shortcuts import render | ||
|
||
from blog.models import Post | ||
|
||
PREVIEW_SIZE=300 | ||
def blog_index(request): | ||
|
||
posts = Post.objects.all().order_by("-created") | ||
context = { | ||
"posts": posts, | ||
"PREVIEW_SIZE": PREVIEW_SIZE, | ||
} | ||
return render(request, "blog/index.jinja2", context) | ||
|
||
def blog_category(request, category): | ||
|
||
posts = Post.objects.filter( | ||
categories__name__contains=category | ||
).order_by("-created") | ||
|
||
context = { | ||
"category": category, | ||
"posts": posts, | ||
"PREVIEW_SIZE": PREVIEW_SIZE, | ||
} | ||
|
||
return render(request, "blog/category.jinja2", context) | ||
|
||
def blog_detail(request, pk): | ||
|
||
post = Post.objects.get(pk=pk) | ||
|
||
context = { | ||
"post": post, | ||
} | ||
|
||
return render(request, "blog/detail.jinja2", context) |