css - django css 文件未加载

标签 css django templates static

我正在努力加载我的 custom.css 文件以在我的 Bootstrap 模板中使用:

错误:

"GET /static/artdb/css/custom.css HTTP/1.1" 404 1785

custom.css 路径:

static/artdb/css/custom.css

基础.html:

{% load static %}
       :
<!-- Custom styles for this template --> 
<link rel="stylesheet" href="{% static "artdb/css/custom.css" %}">

urls.py:

urlpatterns = [
    path('artdb/', include('artdb.urls')),
    path('admin/', admin.site.urls),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

设置.py:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
#STATICFILES_DIRS =(os.path.join(BASE_DIR,"static"),)

知道哪里出了问题吗?

最佳答案

设置.py:

STATIC_URL = '/static/'
STATIC_ROOT= os.path.join(os.path.dirname(BASE_DIR),'static')
STATICFILES_DIRS= [os.path.join(BASE_DIR,'###path to static folder in project###'),STATIC_URL]

关于css - django css 文件未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52590583/

相关文章:

css - 如何在一行中显示 2 个复选框?

c++ - 函数重载,无法推导出模板参数

python - Django 中所有 Celery worker/内存缓存的全局可访问对象

templates - 更好的 Grails 模板

php - 基于自定义字段值的不同 WooCommerce 电子邮件 header

Javascript/JQuery 隐藏和显示

css - 没有样式表正在工作期望 wordpress 中的菜单

CSS 边框的多重渐变发光

python - Django 条件模板标签库加载器

python - 在 Django 开发服务器上打开页面时出现错误状态行异常