django - Azure 上的 Django 应用程序从静态文件中获取图像,而不是从 Bootstrap、Jquery 或 CSS 文件中获取图像
问题描述
在 Azure 上部署了一个具有以下结构的 Django 应用程序:
wwwroot
|---Myproject
|---manage.py
|---oryx-manifest.toml
|---hostingstart.html
|---static //Same static folder and same files from myapp
├── myapp
│ ├── migrations
│ ├── __pycache__
│ ├── static
│ │ │---bootstrap-3.3.7-dist
│ │ │ │--css
│ │ │ │ │--bootstrap.min.css
│ │ │ │ js
│ │ │ │ │--bootstrap.min.js
│ │ │---Datatables
│ │ │ │--jQuery-3.3.1
│ │ │ │ │--jquery-3.3.1.js
│ │ │ │ │datatables.js
│ │ │ │ │datatables.css
| | |---Images
| | | |--myimage.png
| | | |--myimage2.png
│ └── templates
问题是,当我以这种方式在模板上调用静态时:
<script src="{% static 'Datatables/jQuery-3.3.1/jquery-3.3.1.js' %}"></script>
<script src="{% static 'bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap-3.3.7-dist/css/bootstrap.min.css' %}">
<script type="text/javascript" charset="utf8" src="{% static 'Datatables/datatables.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'Datatables/datatables.css' %}">
<img src="{% static 'Images/myimage.png' %}" align="center"/><br>
图像可以完美呈现,但 CDN 数据表和 css 样式不能,并且浏览器控制台会向我抛出此错误:
bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery
at bootstrap.min.js:6
和 :
myappwapp.azurewebsites.net/:1 Refused to apply style from 'https://myapp.azurewebsites.net/static/Datatables/datatables.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
没有意义,在模板上调用脚本的顺序没问题(已经尝试过不同的顺序),此外,图像从那里的同一个静态文件夹加载得很好,如果我在本地机器上运行它,一切都很好......知道怎么了?
提前致谢。
编辑 ////// :settings.py
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
('myapp', os.path.join(BASE_DIR, 'myapp', 'static')),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
解决方案
将以下代码添加到settings.py
.
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
原因
您的文件夹似乎static
处于错误的级别。
相关文章
推荐阅读
- ajax - 在 extjs 中加载应用程序之前未收到 Ajax 响应
- android - 我如何为 SliverAppBar 设置动画以固定并在 customscrollview 顶部滚动?扑
- reactjs - document.querySelector() 第一次点击 React Router Link 时总是返回 null 但之后会正确返回
- python - 如何得出优势比和 p 值以查看差异是否显着?
- c++ - VSCode 无法检测 .h.in 文件中的 CMake 指令
- django - 使用来自其他模型的对象填充 django 模型
- android - 如何让透明容器从背景中脱颖而出?
- qt - Qt Creator qt.qpa.plugin:无法在 Ubuntu 20.04 上加载 Qt 平台插件“xcb”
- javascript - 我的动态网站没有响应特定的按钮点击
- c++ - 使用 WIndows 10、Visual Studio 2019 运行 MongoDB 的基本 C++ 代码时出错