Today’s Offer Enroll today and get access to premium content.
App Store Google Play
Intermediate

What is Django's static files handling?

Django's static files handling involves serving CSS, JavaScript, images, and other files that do not change dynamically. Proper management of static files is crucial for web applications.

To manage static files in Django, follow these steps:

  1. Set the STATIC_URL and STATICFILES_DIRS in your settings.py.
  2. Use the {% load static %} template tag to include static files in your templates.

Here’s how you can set it up:

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]

And to include a CSS file in a template:

{% load static %}