8000 Merge pull request #29 from snipher-marube/main · github/codespaces-django@84f19d3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84f19d3

Browse files
authored
Merge pull request #29 from snipher-marube/main
Added Static and Media Files Serving for Django CodeSpaces
2 parents 5c09f63 + 2e6a64c commit 84f19d3

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-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/

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Welcome to your shiny new Codespace running Django! We've got everything fired u
55
You've got a blank canvas to work on from a git perspective as well. There's a single initial commit with the what you're seeing right now - where you go from here is up to you!
66

77
Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it's gone forever.
8+
To collect static files:
9+
10+
```python
11+
python manage.py collectstatic
12+
```
813

914
To run this application:
1015

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/static/Octocat.png

-1.99 MB
Loading

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