Django 模版继承

1,设计母版页

Test/templates/6/base.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 修正了模板标签的全角字符问题 -->
    {% block title %}
    <title>这个是母版页</title>
    {% endblock %}

</head>
<body>

<table border="1" style="width: 1000px;">
    <tr>
        <td colspan="2" style="height: 30px; text-align: center;">
            这是Top区域,一般用于导航
        </td>
    </tr>

    <tr style="vertical-align: middle; height: 300px;">
        <td style="width: 200px;">
            这左边的的菜单
        </td>
        <td style="width: 500px;">
            <!-- 修正了模板标签的全角字符问题 -->
            {% block content %}
            这个区域随着内容页的变化而变化
            {% endblock %}
        </td>
    </tr>

    <tr>
        <td colspan="2" style="height: 30px; text-align: center;">
            这是版权区域
        </td>
    </tr>
</table>

</body>
</html>

2,设计内容页

Test/templates/6/welcome.html

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    {% extends "6\base.html" %}

    {% block title %}
    <title>这是欢迎页</title>
    {% endblock %}

</head>
<body>

    {% block content %}
    <div style="text-align: center;">
        欢迎来到我的小卖部!
    </div>
    {% endblock %}

</body>
</html>

3,添加视图函数

Test/app6/views.py

复制代码
from django.shortcuts import render

# Create your views here.
def welcome(request):
    return render(request, '6\welcome.html')

4,添加路由地址

Test/app6/urls.py

复制代码
from django.urls import path
from . import views


urlpatterns = [
    path('welcome', views.welcome, name='welcome'),

]

5,访问页面

http://127.0.0.1:8000/app6/welcome

Django 设计组件-CSDN博客

相关推荐
Liue6123123114 分钟前
基于YOLO11-C3k2-Faster-CGLU的路面落叶检测与识别系统实现
python
~央千澈~1 小时前
抖音弹幕游戏开发之第8集:pyautogui基础 - 模拟键盘操作·优雅草云桧·卓伊凡
网络·python·websocket·网络协议
占疏1 小时前
列表分成指定的份数
python
Gaosiy1 小时前
脑电python分析库MNE安装
python·脑机接口·脑电·mne
向量引擎小橙2 小时前
视觉艺术的“奇点”:深度拆解 Gemini-3-Pro-Image-Preview 绘画模型,看这只“香蕉”如何重塑 AI 创作逻辑!
人工智能·python·gpt·深度学习·llama
yaoxin5211233 小时前
324. Java Stream API - 实现 Collector 接口:自定义你的流式收集器
java·windows·python
独行soc3 小时前
2026年渗透测试面试题总结-24(题目+回答)
网络·python·安全·web安全·渗透测试·安全狮
SmartBrain3 小时前
Python 特性(第一部分):知识点讲解(含示例)
开发语言·人工智能·python·算法
Lun3866buzha3 小时前
基于YOLO11-C3k2-FFCM:跳甲虫害叶片智能检测与识别系统
python
Gaosiy4 小时前
技术细节-MNE读取neuroscan curry9版本cdt文件
python·脑机接口·脑电·mne