Django模板扩展无法正常工作 [英] django template extends not working

查看:86
本文介绍了Django模板扩展无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的base.html

This is my base.html

<!DOCTYPE html> 
<head> 
<title> My Site </title>
</head> 
<body>
<div id="wrapper">  
<!-- HEADER START -->
{% block nav %} {% endblock %}
{% block index %} {% endblock %}
</div> 
</body>
</html>

这是我的nav.html

this is my nav.html

{% extends "base.html" %}
{% block nav %}
<div id="header"> 
<div class="inner">

<div class="nav"> 
<ul> 
<li class="current"><a href="index.html">Home</a></li> 
<li><a href="about.html">About</a></li> 
<li><a href="blog_right.html">Blog</a></li>                        
<li><a href="contact.html">Contact</a></li> 
</ul>                     
</div>  
<div class="clear"></div>           
</div><!-- .inner end --> 
</div><!-- #header end --> 
<!-- HEADER END -->
{% endblock %}

这是我的index.html

this is my index.html

{% extends "base.html" %}
{% block index %}
<p> hello </p>
{% endblock %}

我以前做过几次,但我一无所知至于为什么这不起作用?
的网址和视图位于此处。

I have done it several times before before but i am clueless as to why this is NOT working? the urls and views are here.

推荐答案

一切都很好,您遇到的麻烦是您混淆了
,只是在base中命名一个块不会调用它。
标记extends和include之间的区别。
您已混淆扩展到包括。

Well everything is fine, the trouble that you are having is that you are confused, just naming a block in base does not calls it. Mark the difference between extends and include. You have counfused extends to include.

在您的视图中,如果您调用say.html,它将被正确呈现。
所需的效果可以通过将视图中的base.html更改为index.html来实现。

Once in your views if you call say index.html it will be rendered properly. The effect you want can be achieved by changing the base.html in your views to index.html.

希望这会有所帮助。可以在这里阅读更多信息: https://docs.djangoproject.com/en/dev/topics / templates /#template-inheritance

Hope this helps. more can be read here: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance

这篇关于Django模板扩展无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆