Class has no 'objects' member in django

場景

  • 在使用django時,源碼如下
from django.http import HttpResponse
from .models import Question
def index(request):
    boards = Question.objects.all()
    ...
  • 工具檢測報錯如下
: Class 'Question has no objectsmember`

方案

  • 安裝 pylint_django 並對ide(以vscode爲例)添加相應配置
pip install pylint-django
  • 添加配置 User Settings (Ctrl + , or File > Preferences > Settings
"python.linting.pylintArgs": [
        "--load-plugins=pylint_django",
    ]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章