【问题标题】:CSS file not found when trying to load with django尝试使用 django 加载时找不到 CSS 文件
【发布时间】:2025-12-05 16:50:02
【问题描述】:

我没有找到我的 CSS 文件我尝试加载它,我在网上尝试了很多不同的解决方案来修复它,但似乎无法弄清楚原因,而且我的静态文件和模板也在同一个文件中作为项目以及我的 manage.py 文件。

对于我的设置文件

'django.contrib.staticfiles'
 STATIC_URL = '/static/'

在我的基础 html 中

{% load static %}

<meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The css file can be modified for every template if required -->
    {% block style_css %}
    <link rel="stylesheet" type="text/css" href="{% static 'css/style.css' %}" />
    {% endblock %}
    <title>Website Homepage Design Prototype #1</title>

【问题讨论】:

标签: css django


【解决方案1】:
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

STATIC_URL下面添加这一行,它肯定可以工作

【讨论】: