尝试用Django设置一个Bootstrap 4仪表板主题。
如果我双击下载的主题文件夹中的任何.html文件,我将得到一个正确显示的网页,其中的图形和所有内容都正常工作。
但是,当我试图通过Django运行相同的主题时,我只从html文件中获得文本。我对Django很陌生,尤其是Bootstrap,所以我不知道从这里往哪里走。
为了确保所有的静态文件都在正确的位置,我已经将整个主题文件夹复制到了我的静态文件夹中。我还认为我的设置文件配置正确。
INSTALLED_APPS = [
'django.contrib.staticfiles',
]
STATICFILES_DIRS = [os.path.join(BASE_DIR, '/static')]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/以下是命令提示符的部分输出:
System check identified no issues (0 silenced).
October 25, 2018
Django version 2.1.2, using settings 'DataBooth.settings '
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[25/Oct/2018 "GET /dolcegusto/line HTTP/I.I" 200 9722
[25/0ct/2018 21:29:18] "GET / static/ vendor/datatab1es/dataTab1es.bootstrap4.css HTTP/I.I" 404 1753
Not Found: /dolcegusto/vendor/jquery/jquery . min. js
[25/0ct/2018 21:29:18] "GET / static/ vendor/ fontawesome-free/css/all.min.css HTTP/I.I" 404 1741
Not Found: /dolcegusto/vendor/bootstrap/js/bootstrap. bundle. min. js
[25/Oct/2018 "GET /static/css/sb-admin.css HTTP/I.I" 404 1672
Not Found: /dolcegusto/vendor/jquery-easing/jquery.easing.min.js
[25/0ct/2018 21:29:18] "GET / static/ vendor/ bootstrap/css/bootstrap.min.css HTTP/I.I" 404 1738
[25/0ct/2018 21:29:18] "GET /dolcegusto/vendor/jquery/jquery . min. js HTTP/I.I" 404 2231
[25/0ct/2018 21:29:18] "GET /dolcegusto/vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/I.I" 404 2279
Not Found: /dolcegusto/js/demo/chart-pie-demo.js
[25/0ct/2018 21:29:18] "GET /dolcegusto/vendor/jquery-easing/jquery.easing.min.js HTTP/I.I" 404 2273
Not Found: /d01cegusto/vendor/chart.js/Chart . min. js 这件事已经困扰了我好几天了,所以我转向你寻求帮助。
发布于 2018-10-26 15:59:12
设法解决了这个问题。
基本上,我需要将绝对路径添加到settings.py中的静态文件夹中。
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
'/var/www/static/',]之后,我只需在html中加载静态文件。
{% load static %}并将静态标记添加到模板中的每个.css或js链接中,如下所示。
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">因此,基本上,我的问题是,我没有同步引用静态文件夹。
https://stackoverflow.com/questions/52997788
复制相似问题