Cómo va?
Escribo porque no se como resolver en Django la siguiente cuestión (desde mi condición de nuevo en esto):
Tengo dos apps que deben mostrarse en el mismo template.
Es decir, comparten url que es la home, y tienen dos vistas diferentes.
Comparto código.
Se agradece la ayuda
Django==2.0.2 <br>
Python 3.6.5 :: Anaconda, Inc.
views.py
from django.shortcuts import render
from .models import Post
# Create your views here.
def blog(request):
posts = Post.objects.all()
return render(request, 'about/home.html', {'posts': posts})
views.py
from django.shortcuts import render
from .models import Project
# Create your views here.
def portfolio(request):
projects = Project.objects.all()
return render(request, "about/home.html", {'projects':projects})
urls.py
from django.urls import path
from django.contrib import admin
from about import views
from portfolio import views as portfolio_views
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.blog, name = "home"),
path('', portfolio_views.portfolio, name="portfolio"),
]
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Parte de la home.html
<section class="bg-primary" id="about">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto text-center">
{% block background %}
{% for post in posts %}
<h2 class="section-heading text-white"> {{post.title}} </h2>
<hr class="light my-4">
<p class="text-faded mb-4"> {{post.content}} </p>
{% endfor%}
{% endblock%}
<a class="btn btn-light btn-xl js-scroll-trigger" href="#services">iniciemos el viaje</a>
</div>
</div>
</div>
</section>
<section class="p-0" id="portfolio">
<div class="container-fluid p-0">
<div class="row no-gutters popup-gallery">
{% block content %}
{% for project in projects %}
<div class="col-lg-4 col-sm-6">
{% if project.link %}
<a class="portfolio-box" href="{{project.link}}">
{% endif%}
<img class="img-fluid" src="{{project.image.url}}" alt="">
<div class="portfolio-box-caption">
<div class="portfolio-box-caption-content">
<div class="project-name">
{{project.title}}
</div>
</div>
</div>
</a>
</div>
{% endfor%}
{% endblock%}
</div>
</div>
</section>