如何在django中设置tailwind-css或bootstrp和js文件以进行离线工作?

问题描述 投票:0回答:1

在django中,有没有办法链接bootstrap css和js文件以离线工作?我也找到了将 tailwind-css 与我的 django 项目链接的解决方案。

我在全局创建一个静态文件夹。我将这些文件保存在静态文件夹中。然后我尝试使用位于 templates 文件夹中的 base.html 文件中的 和 标签来链接这些文件。我还在 settings.py 文件中设置了 dirs = ['templates'] 。但它们不起作用。

django django-templates tailwind-css bootstrap-5 offline
1个回答
0
投票

1.访问Bootstrap官方网站并下载Bootstrap ZIP文件。 解压 ZIP 文件的内容以获取 Bootstrap CSS 和 JS 文件。

2.在“static”文件夹内,创建“css”和“js”子目录。

3.将 Bootstrap CSS 文件(bootstrap.min.css)复制到“css”文件夹,将 Bootstrap JS 文件(bootstrap.min.js)复制到“js”文件夹。 4.在settings.py中进行设置

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

在您用作模板的主 html 文件中写入

{% load static %}

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
    <!-- Your content here -->

    <script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>

在 html 文件中使用加载静态模板标签。如果这不能解决问题,请转到谷歌并编写“如何使用 bootstrap 与 django 离线”

© www.soinside.com 2019 - 2024. All rights reserved.