1

タグを使用すると{% extends %}、標準の html をプルしません。Django テンプレート タグを初めて使用する場合、不足しているものはありますか。テンプレートフォルダーにもあるindex.htmlファイルにStandard、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 に答える