2013-04-25 213 views
0

當我使用{% extends %}標記它不拉我的標準HTML。是否有新的Django模板標籤丟失?我想將Standard,html添加到我的index.html文件中,該文件也位於templates文件夾中。在模板文件夾Django模板擴展問題

我的索引文件:

{% extends "Standard.html" %} 
{% block maincontent %} 

{% block headcontent %} 
<link rel="stylesheet" type="text/css" href="/media/css/Panels.css" /> 
<link rel="stylesheet" type="text/css" href="/media/css/HostOverview.css" /> 
{% endblock %} 
<script> 
function disaT(c,f){ 
if(c.checked){f.txt1.disabled=false; 
f.submit.disabled=false; 
} 
else{f.txt1.disabled=true; 
f.submit.disabled=false; 
} 
} 
</script> 
<style> 
a:link { 
    color: #39F; 
    text-decoration: none; 
} 
a:visited { 
    text-decoration: none; 
    color: #63C; 
} 
a:hover { 
    text-decoration: none; 
    color: #CCC; 
} 
a:active { 
    text-decoration: none; 
    color: #000; 
} 
</style> 


<div style="display:none" id="dialog" title="Disable Your Account?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>This will disable your account and log you out. You won't be able to log back in. Are you sure you want to continue?</p> 
</div> 

<h1></h1> 

<form name="logger" action="" method="post"> 
<label>Input : </label><textarea name="txtexec" id="txtexec" cols="50"/>{{ txtexec }}</textarea>&nbsp;&nbsp;<input type="submit" name="execute" value="Execute" /><br /><br /> 
<label>Pattern Input : </label><input name="txtpattern" id="txtpattern" type="text" size="100" value="{{ txtpattern }}" /><br /> 
<label>Result : </label><br /> 
</form> 
<P>Discover</P> 
<pre> 
{{ file_content }} 
</pre> 
<P>Console output</P> 
<pre> 
{{ Output_content }} 
</pre> 
<form name="checkin_form" action="#" method="post" enctype="multipart/form-data"><br><br> 
Full pattern : <span style="color:#000; font-size:10px; background:#CCC;" >{{ session_fullpattern }}</span><br><br> 
<label>Check In : </label><input type="checkbox" onclick="disaT(this,this.form)"><br> 
<label>Enter pattern name : </label><input name="txt1" type="text" disabled="true">&nbsp;&nbsp;<input type="submit" name="submit" value="Submit" disabled="true" /> 
</form> 



<div style="clear:both;" /> 


{% endblock %} 

我standard.html頁:

{% extends "Base.html" %} 



{% block head %} 

<link rel="stylesheet" type="text/css" href="/media/css/Standard.css" /> 

<link rel="stylesheet" type="text/css" href="/media/css/Menu.css" /> 

<link rel="stylesheet" type="text/css" href="/media/css/Tooltip.css" /> 

<link rel="Stylesheet" type="text/css" href="/media/css/custom_theme/jquery-ui-1.7.2.custom.css" /> 

<script type="text/javascript" src="/media/js/jquery-1.3.2.min.js"></script> 

<script type="text/javascript" src="/media/js/jquery-ui-personalized-1.6rc6.min.js"></script> 

{% block headcontent %}{% endblock %} 

{% endblock %} 

回答

1

你的繼承和命名的方式。檢查template language documentation。下面的例子也應該給你一個想法。

base.html文件

<html> 
    <head> 
    <!-- this will always be inherited --> 
    {% block head %} 
     <!-- this can be overruled --> 
    {% endblock %} 
    </head> 
    <body> 
    <!-- this will always be inherited --> 
    {% block body %} 
     <!-- this can be overruled --> 
    {% endblock %} 
    </body> 
</html> 

page.html中

{% extends "base.html" %} 

{% block head %} 
    <!-- Hello I am overwriting the base head, but not touching it's body. --> 
{% endblock %} 
1

你嵌套在彼此內,這是很少做正確的事情塊。

您的index.html應該這樣開始:

{% extends "standard.html" %} 

{% block headcontent %} 
<link rel="stylesheet" type="text/css" href="/media/css/Panels.css" /> 
<link rel="stylesheet" type="text/css" href="/media/css/HostOverview.css" /> 
{% endblock %} 
{% block maincontent %} 
... etc 

但你還需要一個地方maincontent進去standard.html:

{% extends "Base.html" %} 

{% block head %} 
.... content ... 
{% endblock %} 
{% block headcontent %}{% endblock %} 
{% block maincontent %}{% endblock %} 
+0

我的主要問題是,我有一個頁面,不給我我的菜單。標準和基礎包含它。它會和url.py文件有什麼關係 – saiyan101 2013-04-25 13:42:23

+0

我不知道你爲什麼這麼想。但是你沒有發佈任何對這個菜單的參考,所以很難說。 – 2013-04-25 13:45:26

+0

菜單位於Standard.html中我可以發佈腳本 – saiyan101 2013-04-25 14:09:19