1

当我使用{% extends %}标签时,它不会通过我的标准 html。Django模板标签有什么新东西吗?我想将 Standard,html 添加到我的 index.html 文件中,该文件也位于模板文件夹中。

我在模板文件夹中的索引文件:

{% 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 %}
4

2 回答 2

2

您将块相互嵌套,这很少是正确的做法。

你的 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 %}
于 2013-04-25T13:06:56.360 回答
1

你的继承和命名是方式。检查模板语言文档。下面的例子也应该给你一个想法。

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 %}
于 2013-04-25T13:06:06.057 回答