2016-04-20 102 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