2016-04-20 130 views
0

我在使用include标记向base.html添加模板时收到错误消息。所有其他模板都可以正确渲染而不会出现问题,但是在尝试添加它时遇到了问题。错误是:包含标记的Django模板错误

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> 

回答

1

你的模板从base.html文件扩展然后需要包含模板,然后需要从base.html扩展,然后需要包含模板,然后需要从base.html扩展,然后需要包含模板,然后需要从基础扩展.html ...

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

+0

错误消失,我可以看到主页罚款。但是,我所包含的模板“recommend.html”并未在主页上显示产品。任何想法? –

+0

@HariraIjaz - 不知道,可能与以'object_list'传递的内容有些问题,但这是一个单独的问题,所以如果需要的话,您应该询问一个新问题。如果这个答案有助于解决这个问题,那么你应该考虑接受它。 – Sayse