【问题标题】:Django template error for include tag包含标签的 Django 模板错误
【发布时间】:2016-08-12 16:25:40
【问题描述】:

我在将模板添加到带有包含标记的 base.html 时收到一条错误消息。所有其他模板都正确呈现,没有问题,但是当我尝试添加它时出现问题。错误是:

RuntimeError at /
maximum recursion depth exceeded in __instancecheck__
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 1.8.5
Exception Type: RuntimeError
Exception Value:    
maximum recursion depth exceeded in __instancecheck__
Exception Location: C:\Python27\lib\site-packages\django\template\base.py in __init__, line 743
Python Executable:  C:\Python27\python.exe
Python Version: 2.7.11
Python Path:    
['C:\\Users\\TOSHIBA\\market\\market',
 'C:\\WINDOWS\\SYSTEM32\\python27.zip',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win',
 'C:\\Python27\\lib\\lib-tk',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'c:\\python27\\lib\\site-packages']

我要添加的模板包括:

{% extends 'base.html' %}
{% block content %}
  <!-- recommend slider -->
  <section class="recommend container">
    <div class="recommend-product-slider small-pr-slider wow bounceInUp">
      <div class="slider-items-products">
        <fieldset class="box-title">
        <legend>Recommended </legend>
        </fieldset>
        <div id="recommend-slider" class="product-flexslider hidden-buttons">
          <div class="slider-items slider-width-col3">
          {% include 'products/product.html' with object_list=products col_class_set="col-sm-2" %}


          </div>
        </div>
      </div>
    </div>
  </section>
  <!-- End Recommend slider -->

{% endblock content %}

我的base.html代码如下:

{% load static %}
{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Dressika Theme">
<meta name="author" content="Harira Ijaz">
<title>Dressika Online Shopping Store</title>
<!-- Favicons Icon -->
<link rel="icon" href="{% static 'images/favicon.png' %}" type="image/x-icon" />
<link rel="shortcut icon" href="{% static 'images/favicon.png' %}" type="image/x-icon" />
<!-- Mobile Specific -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- CSS Style -->
<link rel="stylesheet" href="{% static 'css/animate.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/revslider.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/owl.carousel.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/owl.theme.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/font-awesome.css' %}" type="text/css">
<link rel="stylesheet" href="{% static 'css/product-detail.css' %}" type="text/css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

<!-- Google Fonts -->
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,300,700,800,400,600' rel='stylesheet' type='text/css'>
</head>

<body class="cms-index-index">
<div class="page"> 


{% include 'header.html' %}

{% include 'navbar.html' %}
</div>

  <!-- header service -->

  <!-- end header service -->


{% include 'slider.html' %}
{% include 'offerbanner.html' %}
{% include 'container.html' %}

{% include 'featured.html' %}
{% include 'trending.html' %}


{% include 'middleslider.html' %}

{% include 'recommend.html' %}
{% include 'latestblog.html' %}
{% include 'footer.html' %}


</div>
{% include 'java.html' %}
</body>
</html>

【问题讨论】:

    标签: django python-2.7 django-templates


    【解决方案1】:

    您的模板从 base.html 扩展,然后需要包含模板,然后需要从 base.html 扩展,然后需要包含模板,然后需要从 base.html 扩展,然后需要包含模板, 然后需要从 base.html 扩展...

    从您尝试包含的模板中删除 {% extends 'base.html' %} 以及对块的任何引用。

    【讨论】:

    • 错误消失了,我可以看到主页了。但是我作为“recommend.html”包含的模板没有在主页上显示产品。有什么想法吗?
    • @HariraIjaz - 不知道,作为object_list 传递的内容可能有些问题,但这是一个单独的问题,因此如果需要,您应该提出一个新问题。如果这个答案有助于解决 this 问题,那么您应该考虑接受它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 2018-02-22
    • 2013-02-13
    • 2017-01-05
    • 2012-09-10
    • 2014-05-03
    • 2011-08-10
    相关资源
    最近更新 更多