반응형
settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'main/static')
urls.py
from django.conf.urls import url
from django.views.static import serve
urlpatterns = [
url(r'^media/(?P<path>.*)$', serve,{'document_root': settings.MEDIA_ROOT}),
url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
]
Template에서 사용 방법
{% load static %}
<img src="{% static 'my_app/example.jpg' %}" alt="My image">
서버 실행
python manage.py runserver 0.0.0.0:PORT
'Study > Python' 카테고리의 다른 글
[Python] resolve "failed to create process." issue (0) | 2021.11.05 |
---|---|
[Django] FileUpload 설정 (0) | 2021.09.20 |
[Django] 실행을 위한 기본 명령어 (0) | 2021.09.20 |
Python Tor 사용하기 (darkweb_crawling Project) (0) | 2021.04.26 |
Python Offline Package Install (0) | 2020.09.21 |
댓글