【Django】引入js等静态文件

创建静态目录-app目录/static/app名称

在这里插入图片描述
static目录下一定要新建一个以app命名的文件夹(避免多app引用时冲突)

html模板引入静态资源

{% load static %}
<!doctype html>
<html lang="zh-CN">
    <head>
        <!-- 必须的 meta 标签 -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <!-- Bootstrap 的 CSS 文件 -->
        <link rel="stylesheet" href="{% static "antapp/bootstrap/bootstrap.min.css" %}">
        <title>Hello, world!</title>
    </head>
    <body>
        <h1>Hello, world!</h1>

        <table class="table">
            <thead class="thead-dark">
                <tr>
                    <th scope="col">#</th>
                    <th scope="col">First</th>
                    <th scope="col">Last</th>
                    <th scope="col">Handle</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <th scope="row">1</th>
                    <td>Mark</td>
                    <td>Otto</td>
                    <td>@mdo</td>
                </tr>
                <tr>
                    <th scope="row">2</th>
                    <td>Jacob</td>
                    <td>Thornton</td>
                    <td>@fat</td>
                </tr>
                <tr>
                    <th scope="row">3</th>
                    <td>Larry</td>
                    <td>the Bird</td>
                    <td>@twitter</td>
                </tr>
            </tbody>
        </table>
        <!-- JavaScript 文件是可选的。从以下两种建议中选择一个即可! -->

        <!-- 选项 1:jQuery 和 Bootstrap 集成包(集成了 Popper) -->
        <script src="{% static "antapp/bootstrap/jquery.min.js" %}"></script>
        <script src="{% static "antapp/bootstrap/bootstrap.bundle.min.js" %}"></script>

    </body>
</html>

在这里插入图片描述

写views

def jstest(request):
    return render(request,"jstest.html",{})

在这里插入图片描述

写urls

urlpatterns = [
    path("jstest/",views.jstest),
]

在这里插入图片描述

运行调试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值