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 our GitHub code review bot spots this issue in your pull request it gives this advice:

django-doctorbotsuggested changes just now
views.py
1
+
from example.config import settings

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

Read more
Suggested changes
-
from example.config import settings
+
from django.conf import settings
Commit suggestion
2
+
from django.db import models
Update views.py

Instantly check if you have this issue for free

    Works with tools you use

    Read about how it works.