【问题标题】:context data not getting displayed in inherited template上下文数据未显示在继承的模板中
【发布时间】:2021-07-30 07:28:59
【问题描述】:

基础 HTML

    {% load static %}
             {% include "navigation/navigation.html" with cat=categories only %}
  <!-- base template  -->
           
            {% block content %}
                  some html
        
            
            
            {% endblock%}

模板 B

{% extends "base/index.html" %}
    
    {% block content %}
    
        <!-- product right -->
         Some html
        <!-- //product right -->
    
    
    <!-- //product right -->
    {% endblock %}

我的问题是当我渲染模板时它没有显示我传递给导航栏的上下文,即使单独访问基本模板时上下文显示正常,不知道问题出在哪里,

【问题讨论】:

    标签: django django-views django-templates


    【解决方案1】:

    你不需要这样做

    {% extends "base/index.html" %}
    

    就这样做

    {% extends "index.html" %}
    

    删除 base/index.html

    【讨论】:

    • 但我的 index.html 位于基本文件夹中,您可以猜到该文件夹​​位于模板目录中
    • 我知道,我每次都这样做,我在根目录中有模板文件夹,其中有 base.html 和 index.html,然后我使用 {% extends 'base.html' %} 在我的第二个或任何其他 html 文件中
    猜你喜欢
    • 2021-04-21
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多