Pylint-django worked just fine up to version 2.3.x but since 2.4.0 it reports an error on every python-django file:

Django was not configured. For more information runpylint–load-plugins=pylint_django –help-msg=django-not-configuredpylint(django-not-configured)

This happens on VSCode and I believe I have it correctly configured:

<pre class=”lang-json prettyprint-override”><code> {
“python.linting.pylintArgs”: [
“–load-plugins”,
“pylint_django”,
“–load-plugins”,
“pylint_django.checkers.migrations”,
“–disable=C0114, C0115, W0222”,
“–disable=imported-auth-user”,
“–disable=invalid-name”,
“–disable=line-too-long”
]
}
</code></pre>

This worked perfectly fine, as I said, up to v.2.3.

I raised an issue on their <a href="https://github.com/PyCQA/pylint-django” rel=”noreferrer”>repository</a> but regrettably it was dismissed with little to no visible effort to address it.

For the time being I’m staying with v.2.3.0, which lints with no issues with the above configuration, but would like to know if this is a bug or otherwise.

Did any get into this issue or is it there anything else I’m missing?

Note:

The error message can be hid by adding this value in VSCode’s settings.json:

<pre class=”lang-json prettyprint-override”><code> {
“python.linting.pylintArgs”: [
[…]
“–disable=django-not-configured”,
]
}
</code></pre>

But I’m aware this is sweeping the dust under the carpet.

Answer

Add the --django-settings-module argument the VS Code settings:

<pre class=”lang-json prettyprint-override”><code> {
“python.linting.pylintArgs”: [
[…]
“–disable=django-not-configured”,
“–django-settings-module=<mainapp>.settings”,
]
}
</code></pre>

Change &lt;mainapp&gt; to be your main app directory. For example, if your settings.py was in sweetstuff/settings.py then the argument value would be sweetstuff.settings. This is the same format as you would import the settings module from inside a Python module or the Django shell.

This problem came up for me in some Bitbucket Pipelines. I solved it there by creating the DJANGO_SETTINGS_MODULE as a repository variable which is then made available as an environment variable when Pylint is run.

Source: https://stackoverflow.com/questions/65761250/pylint-django-raising-error-about-django-not-being-configured-when-thats-not-th

110 2 2 0