在Django项目中连接CSS

问题描述 投票:0回答:1

请告诉我错误是什么。运行生成

python manage.py collectstatic
文件后,js脚本可以工作,但css文件未连接。

base.html

<!doctype html>
{% load static %}
<html lang="en">
  <head>
   ....
    <!--Custome CSS-->
    <link rel="stylesheet" href="{% static 'static/css/style.css' %}">
    <title>{% block title %} {% endblock %}</title>
  </head>

文件夹: enter image description here

settings.py

STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / STATIC_URL

我尝试添加文档中的代码:

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 css django
1个回答
0
投票

使用下面。

<link rel="stylesheet" href="{% static 'css/style.css' %}">
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.