BlogListingPage
@route(r"november-2021/$", name="november_2021")
@route(r"^year/(\d+)/(\d+)/$", name="blogs_by_year")
def blog_by_year(self, request, year=None, month=None):
context = self.get_context(request)
return render(request, "blog/latest_posts.html", context)
@route(r'^category/(?P<cat_slug>[-\w]*)/$', name="category_view")
def category_view(self, request, cat_slug):
context = self.get_context(request)
try:
category = BlogCategory.objects.get(slug=cat_slug)
except Exception:
category = None
if category is None:
pass
context["posts"] = BlogDetailPage.objects.filter(categories__in=[category])
return render(request, "blog/latest_posts.html", context)
blog_listing_page.html
<a href="{% routablepageurl page 'latest_blog_posts' %}">View Latest Posts Only</a>
<h2>Categories</h2>
<ul>
{% for cat in categories.all %}
<li>
<a href="{% routablepageurl page "category_view" cat.slug %}">{{ cat.name }}</a>
</li>
{% endfor %}
</ul>
'Back-End > Wagtail, Django' 카테고리의 다른 글
Wagtail 프로젝트 배포 (0) | 2021.12.20 |
---|---|
Wagtail Changing the Admin Display Title (0) | 2021.12.03 |
Wagtail StreamField Options (0) | 2021.12.02 |
Wagtail Custom Page Properties (0) | 2021.12.02 |
Wagtail Custom Admin Tabs (0) | 2021.12.01 |