静的ファイルを読み込もうとしていますが、次のエラーが表示されます:
GET http://127.0.0.1:8000/static/css/user/style.css net::ERR_ABORTED 404 (Not Found) - home:25
GET http://127.0.0.1:8000/static/css/user/style.css 404 (Not Found) - home:25
GET http://127.0.0.1:8000/static/img/logo.png 404 (Not Found) - home:149
GET http://127.0.0.1:8000/static/img/logo.png 404 (Not Found) - home:1
私のコード:
-管理者
設定.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('Welcome.urls')),
path('auth/', include('Authentication.urls')),
path('ad/', include('Ads.urls')),
path('user/', include('UserDashboard.urls')),
path('admin/', include('AdminDashboard.urls')),
]
if settings.DEBUG:
urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
- アプリ
テンプレート
<link href="{% static 'css/user/style.css' %}" rel="stylesheet">
ディレクトリ構造
コードの説明
- 単純にルート ディレクトリに静的ファイルを追加し、それらをテンプレートにインポートしようとしましたが、css ファイルが読み込まれません
- ただし、一部のメディア ファイルは、このメディアのように正常に読み込まれます
<link rel="shortcut icon" type="image/jpg" href="{% static 'img/logo.png' %}" />
。 - また、ディレクトリ構造では、静的フォルダーの同じ場所に img フォルダーと css フォルダーが表示され、image フォルダーの画像は読み込まれますが、css フォルダーの css は読み込まれません。