【问题标题】:How to recieve context to base template django?如何接收基本模板 django 的上下文?
【发布时间】:2019-08-04 21:38:44
【问题描述】:

我有基础模板base.html和page.html和page2.html,它们扩展了base.html

page.html

{% extends 'base.html' %}

page2.html

{% extends 'base.html' %}

当我向 page.html 和 page2.html 发送请求时,我想接收一些关于 base.html 的上下文

我该怎么做?真实的例子,如果可能的话。

现在我将数据写入每个视图,但我认为这是错误的方式。

【问题讨论】:

标签: django django-views django-context


【解决方案1】:

基本模板接收与扩展它的模板相同的上下文数据。所以你可以在基本模板中毫无问题地做这样的事情。

#base.html
<title>{{ title }}</title>

【讨论】:

  • 是的,但我必须将此上下文添加到扩展基本模板的每个视图中。我不想这样做
  • 听起来你需要一个上下文处理器,参考这个问题stackoverflow.com/questions/2893724/…
猜你喜欢
  • 2022-01-18
  • 2013-05-15
  • 2023-04-03
  • 1970-01-01
  • 2021-06-27
  • 2015-09-29
  • 2011-12-07
  • 2021-06-23
  • 2015-11-02
相关资源
最近更新 更多