相关疑难解决方法(0)

使用Pylint和Django

我非常希望将pylint集成到我的python项目的构建过程中,但是我遇到了一个show-stopper:我觉得非常有用的一种错误类型 - : - E1101: *%s %r has no %r member*在使用常见的django字段时会报告错误, 例如:

E1101:125:get_user_tags: Class 'Tag' has no 'objects' member
Run Code Online (Sandbox Code Playgroud)

这是由这段代码引起的:

def get_user_tags(username):
   """
   Gets all the tags that username has used.

   Returns a query set.
   """
   return Tag.objects.filter(  ## This line triggers the error.
       tagownership__users__username__exact=username).distinct()

# Here is the Tag class, models.Model is provided by Django:
class Tag(models.Model):
   """
   Model for user-defined strings that help categorize Events on
   on a per-user basis.
   """
   name = models.CharField(max_length=500, null=False, …
Run Code Online (Sandbox Code Playgroud)

python django static-analysis pylint

137
推荐指数
9
解决办法
4万
查看次数

在vscode中启用pylint_django插件,pylint停止工作

那是我在vscode中的用户设置

{
  "python.pythonPath": "/Users/cristiano/miniconda3/envs/django-rest-2/bin/python",
  "python.linting.pylintEnabled": true,
  "python.linting.enabled": true,
  "python.linting.pylintArgs": [
    "--load-plugins",
    "pylint_django"
  ],
}
Run Code Online (Sandbox Code Playgroud)

我通过conda安装了插件,与pylint相同

pylint                    2.1.1                    py36_0
pylint-django             0.11.1                     py_1    conda-forge
pylint-plugin-utils       0.4                        py_0    conda-forge
Run Code Online (Sandbox Code Playgroud)

如果我注释掉“ python.linting.pylintArgs”部分,则pylint可以正常工作。我已启用该插件来避免特定于Django的错误,例如“ Entity.objects.all()”,但如果启用它,则棉绒将停止工作:它不会突出显示标准错误,也不会警告以前的操作。

我对win和mac使用vscode具有相同的确切行为。我也尝试按照此处所述使用.pylintrc文件,但结果相同:lint停止工作。使用基本conda env或自定义环境的行为相同。

django pylint python-3.x visual-studio-code vscode-settings

9
推荐指数
1
解决办法
1818
查看次数

Django 3: AttributeError: 'AdminSite' 对象没有属性 'Register'

AttributeError: 'AdminSite' 对象没有属性 'Register'

当我进行迁移并打开我的管理部分以添加虚拟信息和图像时,我收到错误消息。

admin.site.Register(Bet, BetAdmin)
Run Code Online (Sandbox Code Playgroud)

到目前为止,我所做的是删除并按回车键,看看它是否是类上的缩进错误。

我还安装了 pylint 以根据建议的答案查看有关错误的更多详细信息。

类没有对象成员

pip install pylint-django
Run Code Online (Sandbox Code Playgroud)

然后我添加到我的settings.json

   {
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
    "workbench.colorTheme": "PowerShell ISE",
    "python.pythonPath": "C:\\Users\\taylo\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe",
    "json.schemas": [

    ],
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django"
    ],

    "[python]": {

    }

}
Run Code Online (Sandbox Code Playgroud)

但它并没有解决任何与问题相关的问题。

仅供参考:我在堆栈上进行了大量搜索和查看,但解决方案看到了拼写错误的位置,例如拼写错误的单词,例如 reqister 而不是 register 拼写错误,并且没有拼写错误。

完整的终端错误

(venv) PS C:\Users\taylo\django\pybet_project> python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\taylo\django\pybet_project\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute …
Run Code Online (Sandbox Code Playgroud)

django django-models django-admin python-3.x

3
推荐指数
1
解决办法
4200
查看次数