Django:ExtendsNode: extends 'base/base.html'> must be the first tag in the template.

学习Django的过程,敲教程的样例过程,到模板继承这里,总是报下面的错误
Django:ExtendsNode: extends 'base/base.html'> must be the first tag in the template._第1张图片

子模板继承的代码如下


<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <title>The Future time</title> </head> <body> {# {% include "include/nav.html" %} #} <h1>My helpful timestamp site</h1> <p>it is will be {{next_time}} after {{hour_offset}}</p> <hr> <p>Thanks for visiting my site.</p> </body> </html> -->
{%extends 'base/base.html'%}

{%block title%} Future Time{%endblock%}
{%block content%}
<p> it is will be {{next_time}} after {{hour_offset}}</p>
{%endblock%}

纠结了好长时间,然后根据错误信息,把未注释的代码放到开头,再试试,结果 ok了, 不知道Django 这样设计的目的。。醉了
如下子类继承

{%extends 'base/base.html'%}

{%block title%} Future Time{%endblock%}
{%block content%}
<p> it is will be {{next_time}} after {{hour_offset}}</p>
{%endblock%}
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <title>The Future time</title> </head> <body> {# {% include "include/nav.html" %} #} <h1>My helpful timestamp site</h1> <p>it is will be {{next_time}} after {{hour_offset}}</p> <hr> <p>Thanks for visiting my site.</p> </body> </html> -->

刷新页面:
Django:ExtendsNode: extends 'base/base.html'> must be the first tag in the template._第2张图片

你可能感兴趣的:(django,python)