Skip to content Skip to sidebar Skip to footer

Using Data From One Django Application In Another

I have a Django blog site. It contains two applications: blog and pages. The blog app lists all blog items as follows: models.py: class News(models.Model): title = models.CharF

Solution 1:

You are almost there. Try this:

views.py

from news.models import News
from django.shortcuts import render

defHomePageView(request):
    context = {}
    news = News.objects.order_by('-date')[:3]  
    context['news']=news 
    return render(request,'home.html',context)

home.html

    {% extends'base.html' %}

    {% block title %}Home{% endblock title %}

    {% block content %}
        <div class="jumbotron">
            <h1class="display-4">Lakeland Cycle Club</h1><pclass="lead">The home of cycling in Fermanagh.</p><pclass="lead"><aclass="btn btn-primary btn-lg"href="{% url 'news_list' %}"role="button">View All Club News</a></p><spanclass="font-weight-bold">
               {%for new in news%}
{{new.title}}
{%endfor%}
            </span>
        </div>
    {% endblock content %}

Post a Comment for "Using Data From One Django Application In Another"