2017-02-12 110 views
0

我想使用基礎模板,然後擴展部分視圖。 extends不起作用,因爲它根本沒有顯示基本標記。如何擴展Django CMS模板?

base.html文件

<div class="container"> 
    {% block content %} 
    {% endblock %} 
</div> 

_hello.html

{% extends 'base.html' %} 
    {% block content %} 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-12 text-center"><h2>Survey About Computer Programming</h2></div> 
     </div> 
     <div class="row"> 
      <div class="col-md-12"> 
       <h3>Programming</h3> 
       <table class="table table-bordered table-striped table-responsive"> 
        <thead> 
         <tr align="center"> 
          <th>Main</th> 
          <th class="text-center">Option1</th> 
          <th class="text-center">Option2</th> 
          <th class="text-center">Option3</th> 
         </tr> 
        </thead> 
        <tbody> 
         <tr> 
          <td>Do you love Programming?</td> 
          <td class="text-center"><input type="radio" class=""></td> 
          <td class="text-center"><input type="radio" class=""></td> 
          <td class="text-center"><input type="radio" class=""></td> 
         </tr> 
        </tbody> 
       </table> 
      </div> 
     </div> 

    </div> 
    <script src="/static/survey/js/plugin.js"></script> 
{% endblock %} 
+1

請顯示您的代碼。 –

+0

這裏沒有粘貼,但'塊'已經提到,沒有區別。 – Volatil3

回答

1

你必須把你的代碼塊內容內。擴展模板將覆蓋基本模板中的塊。

<div class="container"> 
    {% block content %} 
    {% endblock %} 
</div> 
    {% block js_bottom %} 
    {% endblock %} 

_hello.html

{% extends 'base.html' %} 
{% block content %} 
<div class="row"> 
    <div class="col-md-12 text-center"><h2>Survey About Computer Programming</h2></div> 
</div> 
<div class="row"> 
    <div class="col-md-12"> 
     <h3>Programming</h3> 
     <table class="table table-bordered table-striped table-responsive"> 
      <thead> 
       <tr align="center"> 
        <th>Main</th> 
        <th class="text-center">Option1</th> 
        <th class="text-center">Option2</th> 
        <th class="text-center">Option3</th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr> 
        <td>Do you love Programming?</td> 
        <td class="text-center"><input type="radio" class=""></td> 
        <td class="text-center"><input type="radio" class=""></td> 
        <td class="text-center"><input type="radio" class=""></td> 
       </tr> 
      </tbody> 
     </table> 
    </div> 
</div> 
    {% endblock %} 

{% block js_bottom %} 
<script src="/static/survey/js/plugin.js"></script> 
{% endblock %} 
+0

更新了問題。 BLocks已經包含在文件中。 – Volatil3

+0

好吧,這是你的問題的答案。順便說一句,你在你的設計中創建了一個雙「容器」div。 – FeedTheWeb

0

你錯過重要的事情whenver我們這樣創建模板,我們必須確保如CSS,內容每個塊,JS必須proporly在基本HTML文件中定義。當你擴展這個基本模板時,你必須按照需求構建你的內容。就像如果你需要把它擴展了基礎HTML代碼的HTML頁面的一些內容簡單地調用如下 {%塊_block_name_should_be_here%} {%端塊%}

塊名稱可能會像css_part,content_part,js_part這就需要用於html頁面。

+0

這是一個Django CMS插件,並且所有頁眉頁腳已經存在。 – Volatil3