我正在尝试自定义启动项目附带的Pinax主题。出于某种原因,我无法加载外部css样式表。在终端中,当我尝试加载应该加载自定义css的页面时出现此错误:
<link href='{{ STATIC_URL }}css/stylesheet.css' rel='stylesheet' />
这是我的urls.py
from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
url(r"^$", TemplateView.as_view(template_name="homepage.html"), name="home"),
url(r"^admin/", include(admin.site.urls)),
url(r"^account/", include("account.urls")),
]
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
我认为这与settings.py
相关MEDIA_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "media")
# URL that handles the media served from MEDIA_ROOT. Make sure to use
a trailing slash.
# Examples: "http://media.lawrence.com/media/",
"http://example.com/media/"
MEDIA_URL = "/site_media/media/"
STATIC_ROOT = os.path.join(PACKAGE_ROOT, "site_media", "static")
STATIC_URL = "/site_media/static/"
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "static", "dist"),
]
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
答案 0 :(得分:0)
我花了一点时间弄清楚应该放置自定义样式表的位置。 settings.py文件指示:
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "static", "dist"),
]
在我的情况下(因为PROJECT_ROOT目录名为“mysite”),转换为:
mysite/static/dist/css/stylesheet.css
如果您尝试将样式表放在那里(或相对于PROJECT_ROOT的相同位置)。 应该工作。