8000 serving static and media files · martcpp/codespaces-django@777f416 · GitHub
[go: up one dir, main page]

Skip to content

Commit 777f416

Browse files
serving static and media files
1 parent eb08367 commit 777f416

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
db.sqlite3
22
__pycache__/
3+
staticfiles/
4+
.env/
5+
venv/

hello_world/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@
128128
]
129129

130130
STATIC_URL = "static/"
131+
STATIC_ROOT = BASE_DIR / "hello_world" / "staticfiles"
132+
133+
MEDIA_URL = "media/"
134+
MEDIA_ROOT = BASE_DIR / "hello_world" / "media"
135+
131136

132137
# Default primary key field type
133138
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

hello_world/urls.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"""
1616
from django.contrib import admin
1717
from django.urls import path, include
18+
from django.conf import settings
19+
from django.conf.urls.static import static
1820

1921
from hello_world.core import views as core_views
2022

@@ -23,3 +25,6 @@
2325
path("admin/", admin.site.urls),
2426
path("__reload__/", include("django_browser_reload.urls")),
2527
]
28+
if settings.DEBUG:
29+
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
30+
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

0 commit comments

Comments
 (0)
0