django - 无法在 django 2.0 中扩展模板
问题描述
在阅读了两次文档和大量伪教程后,我被 Django 中的模板生成/扩展所困扰。
我的项目结构是:
root
project
templates
base.html
app
templates
child.html
static
imgs
logo.png
在我的 settings.js 上:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
],
},
},
]
我的base.html:
{% load static %}
<html>
<head>
<title>BioPy</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<img src="{% static "imgs/logo.png" %}" alt="BioPy Logo">
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-8">
{% block content %} {% endblock %}
</div>
</div>
</div>
</body>
</html>
我的孩子.html:
{% extend "base.html" %}
{% block content %}
<h1 class="mt-2">Registration</h1>
<hr class="mt-0 mb-4">
{% load crispy_forms_tags %}
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<button type="submit">Sign Up</button>
</form>
{% endblock %}
我收到以下错误:
在简化示例中,BioPy 是项目,BioPyApp 是应用程序,registration.html 是子项。
此致,
解决方案
您正在编写无效的语法,它不是{% extend "base.html" %}
,它是{% extends "base.html" %}
推荐阅读
- javascript - 已部署的 iOS React Native 应用程序中的空白图像
- reactjs - React 中的 Axios GET 请求
- python - 我怎样才能使它更有效率?Python DNA 生成器
- ruby-on-rails - rspec 期望会根据现有的其他期望而变化
- php - LOCK TABLES 会导致 InnoDB 中的死锁吗?
- javascript - 热门在 Meteor 中为自定义域上的 Graphlql 请求设置 HTTP 标头
- html - 如何让我的激活表单与相对位置一起使用?
- reactjs - reduce(prev,curr)函数在react redux中返回未定义
- powershell - 导出完整的 TFS 工作项,包括。PowerShell 的历史
- r - 如何通过变量查找最新数据