簡體   English   中英

使用Pinax無法在Django開發環境中提供靜態文件

[英]Unable to serve static files in a Django development environment with Pinax

我正在嘗試自定義入門項目隨附的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",
]

我花了一點時間弄清楚我應該放置自定義樣式表的位置。 settings.py文件指示:

STATICFILES_DIRS = [
    os.path.join(PROJECT_ROOT, "static", "dist"),
]

在我的情況下(因為PROJECT_ROOT目錄名為“mysite”),轉換為:

mysite/static/dist/css/stylesheet.css

如果您嘗試將樣式表放在那里(或相對於PROJECT_ROOT的相同位置)。 應該工作。

暫無
暫無

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

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