Pylint-django在不是这种情况时引发有关未配置Django的错误(VSCode) [英] Pylint-django raising error about Django not being configured when that's not the case (VSCode)

查看:199
本文介绍了Pylint-django在不是这种情况时引发有关未配置Django的错误(VSCode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pylint-django直到2.3.x版本都可以正常工作,但是从2.4.0版本开始,它在每个python-django文件上报告一个错误:

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.有关更多信息runpylint--load-plugins = pylint_django --help-msg = django-not-configuredpylint(django-not-configured)

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

这是在VSCode上发生的,我相信我已经正确配置了它:

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

    {
      "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"
      ]
    }

就像我说的那样,这在v.2.3之前都可以正常工作.

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

我在他们的存储库上提出了一个问题,但遗憾的是,它几乎没有可见的努力就被​​驳回了解决它.

I raised an issue on their repository but regrettably it was dismissed with little to no visible effort to address it.

暂时我仍停留在v.2.3.0上,该配置对上述配置没有任何影响,但想知道这是一个错误还是其他错误.

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?

注意:

可以通过在VSCode的 settings.json 中添加此值来隐藏错误消息:

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

  {
    "python.linting.pylintArgs": [
        [...]
        "--disable=django-not-configured",
    ]
  }

但是我知道这是扫地毯下的灰尘.

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

推荐答案

在VS Code设置中添加-django-settings-module 参数:

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

  {
    "python.linting.pylintArgs": [
        [...]
        "--disable=django-not-configured",
        "--django-settings-module=<mainapp>.settings",
    ]
  }

< mainapp> 更改为您的主应用程序目录.例如,如果您的 settings.py 位于 sweetstuff/settings.py 中,则参数值将为 sweetstuff.settings .此格式与您从Python模块或Django Shell中导入设置模块的格式相同.

Change <mainapp> 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.

这个问题在某些Bitbucket管道中出现了.我在那里解决了此问题,方法是创建 DJANGO_SETTINGS_MODULE 作为存储库变量,然后在运行Pylint时将其用作环境变量.

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.

这篇关于Pylint-django在不是这种情况时引发有关未配置Django的错误(VSCode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆