Джанго - Как вывести содержимое функции в шаблон
Непонимаю как вывести содержимое функций в шаблон - функции перехода от первого поста к слудующему и обратно. Заранее спасибо за ответ! Есть модель категории и их slug и есть модель посты связвные с категорией ForeignKey со slug.
def get_next_post(post_slug, category_slug):
found = post.objects.first(cat__slug=category_slug, slug__gt=post_slug).order_by("slug")
if not found:
found = post.objects.first(cat__slug_gt=category_slug).order_by("slug")
return found
def get_previous_post(post_slug, category_slug):
found = post.objects.last(cat__slug=category_slug, slug__lt=post_slug).order_by("slug")
if not found:
found = post.objects.last(cat__slug_lt=category_slug).order_by("slug")
return found
def content_post(request, category_slug, post_slug):
found_post = get_object_or_404(post, slug=post_slug, cat__slug=category_slug)
next = get_next_post(post_slug, category_slug)
previous = get_previous_post(post_slug, category_slug)
if next:
next_url = next.get_absolute_url()
next_title = "next"
else:
next_url = reverse("homepage")
next_title = "home"
if previous:
previous_url = previous.get_absolute_url()
previous_title = "previous"
else:
previous_url = reverse("homepage")
previous_title = "home"
return render(
request,
"content/post.html",
{
"post": found_episode,
"next_url": next_url,
"next_title": next_title,
"previous_url": previous_url,
"previous_title": previous_title,
},
)
Шаблон
<div class="bootons-navigation">
<span class="span__bootons-navigatiom"><a href="#" title="Назад">Назад</a></span>
<span class="span__bootons-navigatiom all-seasons"><a href="/" title="Главная">Главная</a></span>
<span class="span__bootons-navigatiom"><a href="#" title="Вперед">Вперёд</a></span>
</div>