Django использование тега шаблона из одного приложения в другое

  • hey guys Im stuck in some problem, as a question, I'm working on a django base website which has 5 pages two apps in it, blog app has posts in it and the other app website is for home_page, so the deal is I have to show the latest posts in home_page with using template tag but with my solution it was never shown.
# index_tag.py Post is what I created in blog models and called here for reuse it 

from django import template
from blog.models import Post


register = template.Library()


@register.inclusion_tag('website/home-latest-posts.html')
def latestposts(arg=3):
    posts = Post.objects.filter(status=1).order_by('published_date')[arg:]
    return {'posts': posts}
<!-- home-latest-posts.html -->

{% load static %}
{% load index_tags %}

<div class="row">
    <div class="active-recent-blog-carusel">
            {% for post in posts %}
                <div class="single-recent-blog-post item">
                    <div class="thumb">
                        <img class="img-fluid" src="{{post.image.url}}" alt="">
                    </div>
                    <div class="details">
                        <div class="tags">
                            <ul>
                                <li>
                                    <a href="#">Travel</a>
                                </li>
                                <li>
                                    <a href="#">Life Style</a>
                                </li>
                            </ul>
                        </div>
                        <a href="{% url 'website:index' pid=post.id %}"><h4 class="title">{{post.title}}</h4></a>
                        <p>{{post.content}}</p>
                        <h6 class="date">{{post.published_date|date:'d M Y'}}</h6>
                    </div>
                </div>
                {% endfor %}
    </div>
</div>

<!-- index.html after many codes this is the template tag that I created -->

{% extends "base.html" %}
{% load static %}
{% load index_tags %}
{% block content %}


<!-- Start blog Area -->

{% latestposts %}

<!-- end blog Area -->

Вернуться на верх