Loading lesson path
Formula
Django does not have a built - in solution for serving static files, at least not in production whenhas to be False.
Formula
We have to use a third - party solution to accomplish this.In this Tutorial we will use WhiteNoise, which is a Python library, built for serving static files.
To install WhiteNoise in your virtual environment, type the command below: pip install whitenoise The result should be something like this:
Formula
Downloading whitenoise - 6.9.0 - py3 - none - any.whl.metadata (3.6 kB)
Downloading whitenoise - 6.9.0 - py3 - none - any.whl (20 kB)Formula
Successfully installed whitenoise - 6.9.0[ notice ] A new release of pip is available: 24.3.1 -> 25.0.1 [ notice ] To update, run:
Formula
python.exe - m pip install -- upgrade pipTo make Django aware of you wanting to run WhitNoise, you have to specify it in the MIDDLEWARE list in settings.py file:
Formula
my_tennis_club/my_tennis_club/settings.py.. MIDDLEWARE = [ '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', ]..
There are one more action you have to perform before you can serve the static file from the example in the previous chapter. You have to collect all static files and put them into one specified folder. You will learn how in the next chapter.