Nice programing

Django에서 정적 파일과 미디어 파일의 차이점은 무엇입니까?

nicepro 2020. 12. 12. 12:26
반응형

Django에서 정적 파일과 미디어 파일의 차이점은 무엇입니까?


Django 1.3으로 이동하고 있는데 미디어와 정적 파일의 분리가 약간 혼란 스럽습니다. 기본값 settings.py은 다음과 같습니다.

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''

# Absolute path to the directory that holds static files.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''

# URL that handles the static files served from STATIC_ROOT.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'

나는에 무엇을 넣어야 MEDIA_ROOT하고 STATIC_ROOT? 별도의 디렉토리 여야합니까? 차이점은 무엇입니까?


정적 파일은 자바 스크립트 / 이미지 등을위한 것이지만 미디어 파일은 사용자가 업로드 한 콘텐츠를위한 것입니다.


Uku Loskit이 말했듯이 정적 파일은 애플리케이션의 CSS 파일, 자바 스크립트 파일, 이미지 등을위한 것입니다. 미디어 파일은 일반적으로 사용자 또는 관리자가 업로드 할 수있는 파일입니다.

일반적으로 당신이 원하는 것 MEDIA_ROOTSTATIC_ROOT별도의 디렉토리로. 점을 명심 STATIC_ROOT관리 명령이 어디 collectstatic찾은 모든 정적 파일을 배치합니다. 프로덕션에서는 .NET으로 STATIC_ROOT시작하는 요청이있을 때 파일을 제공하도록 웹 서버를 구성합니다 STATIC_URL. Django devserver를 개발에 사용하는 경우 자동으로 정적 파일을 제공합니다.

따라서 staticfiles 애플리케이션은 애플리케이션 미디어에서 사용자가 업로드 한 미디어를 분리하여 배포, 백업 및 버전 제어를 더 쉽게 만듭니다. staticfiles 앱 이전에는 개발자가 미디어 파일을 정적 애플리케이션 자산과 혼합하는 것이 일반적이었습니다.

정적 파일을위한 1.3 문서는 꾸준히 개선되었습니다. 자세한 내용은 방법 을 참조하십시오 .

참고 URL : https://stackoverflow.com/questions/5016589/what-is-the-difference-between-static-files-and-media-files-in-django

반응형