我正在开发 django 网站并使用 bootstrap,我可以在 chrome 浏览器上看到样式,但在 firefox 上看不到。
firefox 检查显示 Bootstrap 出现 404 错误,而 chrome 则没有。感谢任何想法。
代码:-
#settings.py
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = '%s/coffestatic/' % (BASE_DIR)
STATICFILES_DIRS = ['%s/website-static-default/'% (BASE_DIR),
("bootstrap", '%s/bootstrap' % (BASE_DIR)),]
HTTP 文件.html
<head>
{% load static %}
<link href="{% static'bootstrap/css/bootstrap.css'%}"rel="stylesheet">
</head>
文件结构
基础目录
|--元素文件夹
|------应用
|--BootstrapDir
|------css
工作流程
- 定义静态文件
- python manage.py collectstatic
- 在 html 中定义样式
- 运行元素
谢谢
最佳答案
我不确定您的 settings.py 文件是否正确,因为它们与我的设置方式不同。话虽这么说,我不是专家,您很可能正在为我运行不同版本的 django。不过我注意到的是您的链接文件上没有文件类型。也许 Chrome 没有这个就很好,但也许 Firefox 没有它就不太适合了。尝试更改:
<link href="{% static'bootstrap/css/bootstrap.css'%}"rel="stylesheet">
到
<link href="{% static'bootstrap/css/bootstrap.css'%}"rel="stylesheet" type="text/css">
只是猜测....
关于python - django css 适用于 chrome 但不适用于 firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47415844/