Web 개발/Django

Django Static 파일 관리하기 (image, JavaScript, CSS, etc.)

yororing 2024. 3. 20. 15:32

개발 중 Static 파일 제공

  • If you use django.contrib.staticfiles as explained above, runserver will do this automatically when DEBUG is set to True.
  • If you don’t have django.contrib.staticfiles in INSTALLED_APPS, you can still manually serve static files using the django.views.static.serve() view.
  • This is not suitable for production use.
  • For example, if your STATIC_URL is defined as static/, you can do this by adding the following snippet to your urls.py:
    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        # ... the rest of your URLconf goes here ...
    ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)​