新建base.html页面
把相同的页面代码放到base.html中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'bootstrap5/bootstrap.min.css' %}">
<script src="{% static 'bootstrap5/popper.min.js' %}"></script>
<script src="{% static 'bootstrap5/bootstrap.min.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/base.css' %}">
{% block head %}{% endblock %}
</head>
<body>
<header class="p-3 text-bg-light border-bottom mb-3">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
<img src="{% static 'image/logo.png' %}" alt="" height="40">
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="#" class="nav-link px-2 text-secondary">首页</a></li>
<li><a href="#" class="nav-link px-2 text-secondary">发布博客</a></li>
</ul>
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" role="search">
<input type="search" class="form-control" placeholder="搜索..." aria-label="Search">
</form>
<div class="text-end">
<button type="button" class="btn btn-outline-primary me-2">登录</button>
<button type="button" class="btn btn-primary">注册</button>
</div>
</div>
</div>
</header>
<main class="container bg-white p-3 rounded">
{% block main %}{% endblock %}
</main>
</body>
</html>
改造index.html
{% extends 'base.html' %}
{% block title %}首页{% endblock %}
{% block main %}
<h1>博客列表</h1>
<div class="row row-cols-2 row-gap-4">
<div class="col">
<div class="card">
<div class="card-header">
<a href="#">Django5实战教程</a>
</div>
<div class="card-body" style="height: 100px;">
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
</div>
<div class="card-footer text-body-secondary d-flex justify-content-between">
<div>
<img src="{% static 'image/avatar.webp' %}" class="rounded-circle" width="30" height="30" alt="">
钢铁侠
</div>
<div>发布时间:2024年10月6日 10:40</div>
</div>
</div>
</div>
</div>
{% endblock %}
改造login.html
{% extends 'base.html' %}
{% block title %}登录{% endblock %}
{% block main %}
<div class="m-auto" style="max-width: 330px;">
<h1>登录</h1>
<form class="mt-3">
<div class="mb-3">
<label class="form-label">邮箱</label>
<input type="email" name="email" placeholder="请输入邮箱" class='form-control'>
</div>
<div class="mb-3">
<label class="form-label">密码</label>
<input type="password" name="password" placeholder="请输入密码" class='form-control'>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name='remember' value="1" id="flexCheckDefault">
<label class="form-check-label" for="flexCheckDefault">
记住我
</label>
</div>
<div class='mb-3'>
<button class='btn btn-primary w-100'>登录</button>
</div>
</form>
</div>
{% endblock %}
改造register.html
{% extends 'base.html' %}
{% block title %}注册{% endblock %}
{% block main %}
<div class="m-auto" style="max-width: 330px;">
<h1>请注册</h1>
<form class="mt-3">
<div class="mb-3">
<label class="form-label">用户名</label>
<input type="text" name="username" placeholder="请输入用户名" class='form-control'>
</div>
<div class="mb-3">
<label class="form-label">邮箱</label>
<input type="email" name="email" placeholder="请输入邮箱" class='form-control'>
</div>
<div class="mb-3">
<label class="form-label">验证码</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="验证码" aria-label="Recipient's username"
aria-describedby="button-addon2">
<button class="btn btn-outline-secondary" type="button">获取验证码</button>
</div>
</div>
<div class="mb-3">
<label class="form-label">密码</label>
<input type="password" name="password" placeholder="请输入密码" class='form-control'>
</div>
<div class='mb-3'>
<button class='btn btn-primary w-100'>注册</button>
</div>
</form>
</div>
{% endblock %}
改造blog_detail.html
{% extends 'base.html' %}
{% block title %}博客详情{% endblock %}
{% block main %}
<h1>博客详情</h1>
<hr>
<div class="mt-2">
<img src="{% static 'image/avatar.webp' %}" class="rounded-circle" width="30" height="30" alt="">
<span class="ms-2">钢铁侠</span>
<span class="ms-2">于</span>
<span class="ms-2">发布时间:2024年10月6日 10:40</span>
</div>
<hr>
<div class="py-2">
博客详情
</div>
<hr>
<div class="mt-2">
<h3>评价(10)</h3>
<form action="" method="POST">
<div class="mt-2">
<input type="text" class="form-control" placeholder="请输入评论">
</div>
<div class="text-end mt-2">
<button type="button" class="btn btn-primary">评价</button>
</div>
</form>
</div>
<div class="mt-2">
<ul class="list-group list-group-flush">
<li class="list-group-item mb-3">
<div class="d-flex justify-content-between text-body-secondary">
<div class="user-info">
<img src="{% static 'image/avatar.webp' %}" class="rounded-circle" width="40" height="40" alt="">
<span class="ms-2">钢铁侠</span>
</div>
<div class="create-time" style="line-height: 40px;">
发布时间:2024年10月6日 10:40
</div>
</div>
<div class="mt-2">
评价内容
</div>
</li>
</ul>
</div>
{% endblock %}
改造pub_blog.html
{% extends 'base.html' %}
{% block title %}发布博客{% endblock %}
{% block head %}
<link rel="stylesheet" type="text/css" href="{% static 'wangeditor/style.css' %}">
<script type="text/javascript" src="{% static 'wangeditor/index.js' %}"></script>
<script type="text/javascript" src="{% static 'js/pub_blog.js' %}"></script>
<style type="text/css">
#editor—wrapper {
border: 1px solid #ccc;
z-index: 100; /* 按需定义 */
}
#toolbar-container {
border-bottom: 1px solid #ccc;
}
#editor-container {
height: 500px;
}
</style>
{% endblock %}
{% block main %}
<h1>发布博客</h1>
<div class="mt-2">
<form>
<div class="mb-3">
<label class="form-label">标题</label>
<input type="text" name="title" placeholder="请输入标题" class="form-control">
</div>
<div class="mb-3">
<label class="form-label">分类</label>
<select class="form-select" name='category'>
<option value="1">Python</option>
<option value="2">前端</option>
<option value="3">大数据</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">内容</label>
<div id="editor—wrapper">
<div id="toolbar-container"><!-- 工具栏 --></div>
<div id="editor-container"><!-- 编辑器 --></div>
</div>
</div>
<div class="mb-3 text-end">
<button class="btn btn-primary">发布</button>
</div>
</form>
</div>
{% endblock %}