gpt4 book ai didi

python - Django:我的 css 静态路径不存在

转载 作者:太空宇宙 更新时间:2023-11-04 01:14:40 25 4
gpt4 key购买 nike

我的链接是这样的:

<link rel="stylesheet" type="text/css" href="{% static 'css/background.css' %}">

这很好,因为它得到了我想要的路径,即 href="/static/css/background.css"。我使用 {% load static}。我的 INSTALLED_APPS 中有 django.contrib.staticfiles。这是关于我的 settings.py 的更多相关信息:

STATIC_URL = '/static/'

STATICFILES_DIR = [
os.path.join(BASE_DIR, "static"),
]

但我很确定这也是正确的。我的问题是我的本地服务器找不到 static/css/background.css。我知道这是因为 http://localhost:8000/static/css/background.css给我一个 404 错误。我不知道为什么会这样,因为这是我的元素文件路径:

元素

  Project

src

static

css
background.css

最佳答案

你设置你的url路径了吗?这是官方 Django 文档的一个片段。

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

关于python - Django:我的 css 静态路径不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50457731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com