簡體   English   中英

Django Web 應用程序“不允許加載本地資源/.css 文件”

[英]Django web app "Not allowed to load local resource /.css file"

我無法在我的網頁中加載 css 文件它只是給了我一個沒有 css 元素的簡單頁面,如屏幕截圖所示,並說它無法加載本地資源頁面並檢查元素我已經在設置中加載了靜態文件

STATIC_URL = '/static/'
STATICFILES_DIRS=[

    os.path.join(BASE_DIR,'assets')

]
STATIC_ROOT=os.path.join(BASE_DIR,'assets')

添加網址

static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

在 html 中使用這個

{%load static%}
<head>

<meta charset="UTF-8">
<title>LOGIN</title>
<link rel="stylesheet" href="{% static 'assets/styles/style.css' %}">
</head>

也做了 manage.py collectstatic

按照文檔不知道我哪里出錯了

您應該使用link標簽:

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

這足以加載文件; 所以你不需要以下內容:

{% include "assets/styles/style.css" %}

而且,如果您的 css 文件在BASE_DIR/assets/style.css ,您應該像下面一樣更改您的設置:

STATICFILES_DIRS=[

    os.path.join(BASE_DIR,'assets')
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM