【问题标题】:Django not showing text after extending [closed]扩展后Django不显示文本[关闭]
【发布时间】:2021-02-05 19:05:59
【问题描述】:

我正在学习 Django 并扩展了两个 html 文件。扩展后,我得到了我想要的颜色,但没有文字。我的代码如下:

base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hello</title>
</head>

<body bgcolor="red">
    
    {% block content %}

    {% endblock %}
    
</body>
</html>

home.html

{% extends 'base.html' %}

{% block conent %}

<h1>Hello {{name}}!!!!!!!</h1>

{% endblock %}

views.py

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def home(request):
    return render(request, 'home.html', {'name': 'Bob'})

base.html 之前

Before base.html

base.html 之后

After base.html

【问题讨论】:

  • 您在home.html 中有错字。而不是{% block conent %},它应该是{% block content %}
  • 在没有看到您的评论的情况下添加了答案

标签: python html django


【解决方案1】:

您的home.html 中有错字。它的内容,而不是内容

{% block content %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2017-08-28
    • 2014-04-20
    • 1970-01-01
    • 2015-01-20
    相关资源
    最近更新 更多