1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
theorangeone.net-legacy/project/blog/views.py

20 lines
694 B
Python

from django.views.generic import TemplateView
from .utils import get_post, reformat_date
from django.http import Http404
class BlogView(TemplateView):
template_name = "blog/post.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['blog'] = self.blog_data
context['blog']['date'] = reformat_date(self.blog_data['date'])
context['html_title'] = self.blog_data['title']
return context
def dispatch(self, request, *args, **kwargs):
self.blog_data = get_post(kwargs['slug'])
if not self.blog_data:
raise Http404
return super().dispatch(request, *args, **kwargs)