Hey bro don't need to panic. Let's do it.
settings.py
file.from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
INSTALLED_APPS = [
'whitenoise.runserver_nostatic', # put it at the top
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# applications are always at the bottom
'hotdog_app',
'corsheaders',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # put it at the bottom
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
python manage.py collectstatic
.In staticfiles folder, you’ll find two main subfolders: an admin
folder, which can be deleted if you’re not using the admin panel, and folders named after each of your apps. Within these app folders, you can add as many CSS and JavaScript files as needed. To enable static file loading, include {% load static %}
at the top of your HTML file and add css link in head tag as <link rel="stylesheet" href="{% static 'test_app/css/custom.css' %}">
, if you want to add js link you can do that like <script type="module" src="{% static 'test_app/js/main.js' %}"></script>
.
Also, could you confirm if you're planning to deploy your application on Vercel or another platform? Most platforms follow a similar process for static file management, but it’s important to be aware of any platform-specific requirements in case issues arise. For more detailed information on configuring WhiteNoise, refer to the official documentation https://whitenoise.readthedocs.io/en/stable/django.html