【发布时间】:2016-11-17 22:32:51
【问题描述】:
我是第一次开发 Django 应用程序。如何将多个模型传递给模板
views.py
from django.views.generic import ListView, DetailView
from django.utils import timezone
from LastAlly.models import Article, Episode
class IndexView(ListView):
queryset = Article.objects.all().order_by("-date")[:3]
template_name = 'index.html'
urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.views.generic import ListView, DetailView
from LastAlly.views import IndexView
urlpatterns = [
url(r'^$', IndexView.as_view(), ),
]
【问题讨论】:
-
“将多个模型传递给模板”是什么意思?
-
我需要使用 Episode 模型来索引模板。
标签: python django templates model