django5博客项目实战-用bootstrap5实现博客详情页面

创建一个blog_detail.html

代码为

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的博客</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' %}">
</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">
    <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>
</main>
</body>
</html>

输入框样式

https://getbootstrap.com/docs/5.3/forms/form-control/

 评论列表样式参考

https://getbootstrap.com/docs/5.3/components/list-group/

创建视图函数

def blog_detail(request,blog_id):
    return render(request,'blog_detail.html')

 创建路由

from django.urls import path
from . import views

app_name = 'blog'

urlpatterns = [
    path('',views.index,name='index'),
    path('blog/<blog_id>',views.blog_detail,name='blog_detail'),
]

测试访问效果

http://127.0.0.1:8000/blog/2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值