为什么我不能将我的静态文件提供给 Django?

Why can't I serve my static files to Django?

在任何人将其标记为重复之前,我已经看过所有其他关于类似主题的问题并尝试了所有解决方案但没有效果。

我的 Django 应用程序很小,我很乐意从同一台服务器提供静态文件

settings.py我有

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

我已经将我的申请上传到服务器并且运行

python.manage.py collectstatic

我所有的静态文件都在 staticfiles

下的适当目录中
project-root
├── staticfiles
│   ├── css
│   │   ├── base.css
│   ├── js
│   │   ├── common.js

在我的html我有

{% load static %}
<link href="{% static 'css/base.css' %}" rel="stylesheet">

加载页面时出现错误

Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

我想这是因为找不到css文件

我哪里错了?我需要提供更多信息吗?

project_name - app_name - static - app_name - css/js file

<link rel="stylesheet" href="{% static 'app_name/style.css' %}">

我的问题已通过安装 whitenoise 软件包得到解决。 (关于这个问题的类似问题的回复我还没看到这个推荐)

pip install whitenoise

并将其添加到settings.py

的中间件部分
MIDDLEWARE = [
    ...
    'whitenoise.middleware.WhiteNoiseMiddleware', 
    ...
]

我所有的静态文件现在都已加载,网站无需进一步配置即可完美运行

(我假设问题可能是由站点主机的服务器设置中的一个怪癖引起的。)