Django

[Django] Debug=False 설정 시 static 이 깨지는 오류

torimuk 2021. 12. 27. 15:53

Problem: Debug=False 로 설정한 후 서버에 올릴 시 static이 깨지는 오류 발생.

 

Solution:
1. runserver 뒤에 --insecure 인자 추가.

python manage.py runserver ... --insecure

2. urls.py 수정

url(r’^static/(?P.+)’, serve, kwargs={‘insecure’: True})

2-2.

urlpatterns = […]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT, insecure=True)

 


물론 기본적으로 static 파일은 웹 서버가 제공해야 한다.
보안상의 이유로 Debug=False 인 경우 정적 파일 접근을 금지하기 때문이다.

URL: https://fbdjango.wordpress.com/2016/08/25/183432721693235_1080086298694535/

 

간단한 팁 하나 올립니다. django에서 가끔 로컬에서 DEBUG=False로 놓고 테스

Permalink:   박영록 간단한 팁 하나 올립니다. django에서 가끔 로컬에서 DEBUG=False로 놓고 테스트하고 싶을 때가 있죠? 그런데 그러면 static file이 서빙되지 않아서 원하는 테스트가 안될 때가 있습니

fbdjango.wordpress.com

https://senticoding.tistory.com/82

 

[Django] Django에서 static 과 media 이용하기. DEBUG=False일 때 static

문제점 Django 를 막 입문한 뒤 프로젝트를 배포하려고 settings.py 에서 DEBUG=False 로 바꾸는 순간 경악을 금치못할 수 있다. DEBUG=False 로 바꾸는 순간 runserver 로 서버를 돌릴 시 static file, media fil..

senticoding.tistory.com

https://docs.djangoproject.com/en/4.0/howto/static-files/

 

How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django

Django The web framework for perfectionists with deadlines. Overview Download Documentation News Community Code Issues About ♥ Donate

docs.djangoproject.com

 

'Django' 카테고리의 다른 글

[Django] Function Based View 환경에서 Swagger 사용하기  (0) 2022.04.28
[Django API] Django + JWT  (0) 2022.04.26
[Django] 500 Internal server error handler  (0) 2022.02.14
[Django] settings 파일  (0) 2021.12.22
[Django] request header 읽기  (0) 2021.12.22