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博客

相关推荐
rannn_11111 分钟前
【学以致用|python自动化办公】OCR批量识别自动存为Excel(批量识别发票)
python·ocr·excel·财务
AI视觉网奇40 分钟前
pycharm 默认终端设置 cmd
ide·python·pycharm
言之。44 分钟前
LiteLLM:让LLM调用变得简单统一
后端·python·flask
ZhengEnCi1 小时前
Python_try-except-finally 完全指南-从异常处理到程序稳定的 Python 编程利器
后端·python
jarreyer1 小时前
常见分析方法与对应图表汇总
python·信息可视化·数据分析
m0_64880493_江哥1 小时前
用正则方法从中英文本提取英文的python示例
python·mysql·正则表达式
N0nename1 小时前
TR3--Transformer之pytorch复现
人工智能·pytorch·python
Full Stack Developme1 小时前
jdk.random 包详解
java·开发语言·python
m***记2 小时前
Python 数据分析入门:Pandas vs NumPy 全方位对比
python·数据分析·pandas
MYX_3092 小时前
第七章 完整的模型训练
pytorch·python·深度学习·学习