django - Django:包含标签后出现严重错误
问题描述
在我在 django 模板中使用包含标签后,我得到了错误。
错误:
RecursionError at /home/
maximum recursion depth exceeded
Error during template rendering
我的 base.html 文件。
<html>
{% load static %}
<some static css here>
{% include "inc/header.html" %}
{% block header %} HEADER {% endblock header %}
<some static js here>
</html>
我的头文件是
{% extends 'base.html' %}
<p> test header</p>
解决方案
您现在正在同时做两件事,您正在扩展“base.html”文件,同时您正在包含“header.html”。
这就是为什么你会遇到递归问题。
为了使事情正常工作,您需要删除 {% include %} 代码块。所以你的头文件看起来像
{% extends 'base.html' %}
{% block header %}
<p> Test Header </p>
{% endblock %}
虽然你的 base.html 不需要'HEADER' beetwen 你的 {% block header %} 标签,所以它应该看起来像:
<html>
{% load static %}
<some static css here>
{% block header %}{% endblock %}
<some static js here>
</html>
推荐阅读
- php - 如何仅编辑 Opencart 上选定字段的用户权限?
- angular-material - How to customize `mat-form-field`
- visual-studio - Web API works locally but doesn’t work on azure
- mysql - 检查表 A 中的所有行在表 B 中是否具有特定值,包括 GROUP BY
- laravel - Laravel project wont serve to given ip via Homestead
- python - Python 文件 I/O 明显慢于 OpenCV imread
- docker - 如何在 Docker 中安装 Adafruit-GPIO 库
- node.js - 如何使用nodejs将mongo中的大集合保存到文本文件中?
- ruby-on-rails - ActiveRecord:has_many 选择仅限于另一个模型的 has_many
- html - 在 CSS 动画中使用右箭头的最佳方法