Importing setting file directly

Using from django.conf import settings simplifies the code and makes it more maintainable.

It's preferable to use from django.conf import settings instead of importing the settings file directly.

Importing directly can trigger a race condition when your code imports settings before the app is ready.

Overriding settings in tests is simplified when using django.conf.settings as you can then use Django's modify_settings and django-pytest's settings fixture, which rely on the code using django.conf.settings.

If we spot this issue in your GitHub pull request we give this advice:

views.pymaintainabilitymedium
-
from example.config import settings
+
from django.conf import settings
from django.db import models

Using from django.conf import settings simplifies the code and makes it more maintainable.

Read more
Protect your pull requests from over 40 types of common Django technical debts with our GitHub code review bot.

Configuring this check

Django Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code direct-import-settings in your pyproject.toml file.

Read more about configuring Django Doctor.