From 1d44edc456f31a7b5b25c00be8a9135a6fbb9ffc Mon Sep 17 00:00:00 2001 From: jhyns Date: Tue, 16 May 2023 21:48:59 +0900 Subject: [PATCH] Specify static, media files url --- config/settings/base.py | 6 ++++++ config/urls.py | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index a6a3d03..04e04f6 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -115,6 +115,12 @@ USE_TZ = True # https://docs.djangoproject.com/en/4.2/howto/static-files/ STATIC_URL = "static/" +STATIC_ROOT = os.path.join(BASE_DIR, "static") + +# Media files + +MEDIA_URL = "media/" +MEDIA_ROOT = os.path.join(BASE_DIR, "media") # Default primary key field type # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field diff --git a/config/urls.py b/config/urls.py index 469665f..1e3a4da 100644 --- a/config/urls.py +++ b/config/urls.py @@ -14,11 +14,17 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings +from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path -urlpatterns = [ - path("admin/", admin.site.urls), - path("", include("market.urls")), - path("user/", include("user.urls")), -] +urlpatterns = ( + [ + path("admin/", admin.site.urls), + path("", include("market.urls")), + path("user/", include("user.urls")), + ] + + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +)