Mastering Django - Errata and Updates - Python Django Tutorials

Mastering Django – Errata and Updates

Path Settings Change in Django 3.1

From Django 3.1, the Django setting.py file replaces the os module from Python with pathlib.

So:

import os

Is now:

from pathlib import Path

For existing projects, this will not affect the operation of your code. If you start a new project with Django 3.1, however, the code in my books, courses and website will break on the DIRS and STATICFILES_DIRS settings.

You have two options to resolve this problem. The simplest is to add import os to your Django 3.1 settings file.

The second option is to change your settings to use pathlib. This is the best option, as Django will use pathlib from 3.1 onwards, so you might as well get used to the change.

You need to make two changes.

Change:

'DIRS': [os.path.join(BASE_DIR, 'myclub_site/templates')],

in your TEMPLATES setting to:

'DIRS': [BASE_DIR / 'myclub_site/templates'],

And change:

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

to:

STATICFILES_DIRS = [BASE_DIR / 'myclub_site/static')]