【发布时间】:2014-06-27 21:07:01
【问题描述】:
我正在构建我的第一个 django 网站,但我无法理解支持网站首页所需的对象。
首页的结构很像12 Factor App的首页,我想知道django对象是什么;我需要模型、视图等来实现这一点吗?
该页面将包含几个标题,其中的文本很少更改。此文本下方将是指向网站其他部分的链接列表。所有内容都将通过管理应用程序添加。
目前我有以下模型:
class FrontPage(models.Model):
introduction = models.CharField(max_length = 4000)
updates = models.CharField(max_length = 4000)
我的视图(简化)如下所示:
def indexpage(request):
front_page = get_object_or_404(FrontPage, pk=1)
collection_list = CarCollection.objects.orderby('the_year')
return render(request, 'index.html', {'collection': collection_list, 'frontpage': front_page})
我传递给我的模板并且我的页面按预期显示,我看到了文本和链接。
但是我确信必须有一种更“django”类型的方式来开发这种类型的页面,因此非常感谢任何帮助或建议。
如果需要我使用 Django 1.6
【问题讨论】:
标签: django django-models django-views