模板继承报错:
extends ‘base/base.html‘> must be the first tag in the template
base.html如下:
<!-- {% load static %}
{{name}} <img src="{% static "images/test.jpg" %}" alt="test-jpg"> -->
{% extends "base.html" %}
{% block mainbody %}
<p> 继承 base.html 文件</p>
{% endblock %}
最后发现,{%block mainbody %}必须放在base.html的第一行才可以,就算前面有注释也不行。
更改:
{% extends "base.html" %}
{% block mainbody %}
<p> 继承 base.html 文件</p>
{% endblock %}
<!-- <!DOCTYPE html>
<html lang="en">
<head>
刷新:
Django踩坑之ExtendsNode: extends 'base/base.html'> must be the first tag in the template.