django css文件未加载

时间:2018-10-01 11:56:57

标签: css django templates static

我正在努力加载要在我的引导模板中使用的custom.css文件:

错误:

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

custom.css的路径:

static/artdb/css/custom.css

base.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)

settings.py:

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

知道有什么问题吗?

1 个答案:

答案 0 :(得分:1)

settings.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]