简体   繁体   English

Django模板扩展问题

[英]Django template extend issue

When I use {% extends %} tag its not pulling through my standard html. 当我使用{% extends %}标签时,它不会通过我的标准html。 Is there something am missing am new to Django template tags. 有没有遗漏的东西是Django模板标签的新功能。 I want to add the Standard,html into my index.html file which also resides in the templates folder. 我想将Standard,html添加到我的index.html文件中,该文件也位于templates文件夹中。

My index file in the template folder: 我在模板文件夹中的索引文件:

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

My standard.html page: 我的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 %}

Your inheritance and naming is way of. 你的继承和命名是方式。 Examine the template language documentation . 检查模板语言文档 The example below should give you an idea aswell. 下面的例子也应该给你一个想法。

base.html 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 page.html中

{% extends "base.html" %}

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

You're nesting blocks inside each other, which is rarely the right thing to do. 你在彼此之间嵌套,这很少是正确的事情。

Your index.html should start like this: 你的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

but then you also need a place for maincontent to go in standard.html: 但是你还需要一个maincontent的地方进入standard.html:

{% extends "Base.html" %}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM