[英]Can't get Django Template Inheritance to work
This seems so simple and yet it refuses to work...这看起来很简单,但它拒绝工作......
I have my base.html file:我有我的 base.html 文件:
{% load static %}
<html>
<head>
<meta charset="utf-8">
<title>
{% block title %}
Simple Skeleton
{% endblock title %}
</title>
and my home.html file:和我的 home.html 文件:
{% extends "base.html" %}
<% block title %>
Resource List
<% endblock %>
(they are both a bit longer but I feel this is all that is necessary) (它们都有点长,但我觉得这就是所有必要的)
The home.html completely fails to overwrite the sections within the code blocks - the page title remains "Simple Skeleton" and not "Resource List" despite me accessing the home.html file. home.html 完全无法覆盖代码块中的部分 - 尽管我访问了 home.html 文件,但页面标题仍然是“简单骨架”而不是“资源列表”。
What am I doing wrong?我究竟做错了什么?
Django template tags are written between {% … %}
, not , so <% … %>
{% block title %}
, not : <% block title %>
Django 模板标签写在
{% … %}
之间,而不是 ,所以<% … %>
{% block title %}
,而不是 :<% block title %>
{% extends "base.html" %} {% block title %} Resource List {% endblock %}
By not using the proper template tag, Django will not render this content: it is content outside a block, so it will not have an effect on the inherited template.如果不使用正确的模板标签,Django 将不会呈现此内容:它是块外的内容,因此它不会对继承的模板产生影响。
You have a typo error in home.html
.您在
home.html
中有拼写错误。 Use {% %}
for template tags instead of .<% %>
对模板标签使用
{% %}
而不是 。<% %>
{% extends "base.html" %}
{% block title %}
Resource List
{% endblock %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.