Python Django:无法访问View.py中模型类的object属性

Python Django:无法访问View.py中模型类的object属性,python,django,Python,Django,Django:无法访问模型类上的object属性 我正忙于构建一个Django应用程序,该应用程序从数据库返回一组需求。但是,我在View.py中遇到ab ObjectDoesNotExist异常。我正在使用Visual Studio 2015。我将感谢所有帮助解决此错误 下面是Models.py中的代码: from django.db import models class Requirement_Matrix(models.Model): RequirementName =

Django:无法访问模型类上的object属性

我正忙于构建一个Django应用程序,该应用程序从数据库返回一组需求。但是,我在View.py中遇到ab ObjectDoesNotExist异常。我正在使用Visual Studio 2015。我将感谢所有帮助解决此错误

下面是Models.py中的代码:

from django.db import models

class Requirement_Matrix(models.Model):    
    RequirementName = models.CharField(max_length=128)
在Views.py中,Visual Studio 2015中的intellisense表示对象(第12行)是未知类型。运行程序时,它会引发“对象不存在”异常

01 from django.core.exceptions import ObjectDoesNotExist
02 from ScopeManagement.models import Requirement_Matrix
03
04
05 def index(request):
06    # Query the database for a list of requirements for a specific project.
07    # Place the list in our Requirement_dict dictionary which will be passed to the 
08  #template engine.
09    
10    try:
11
12        Requirement_list = Requirement_Matrix.objects.all() ### <- Visual Studio 2015 
13  # is saying that objects is unknown type and then it raises an object does 
14  # not exist exception
15
16        Requirement_dict = {'requirements': Requirement_list}
17
18    except ObjectDoesNotExist:
19        print ('Does Not Exist!')
20    
21    # Render the response and send it back
22    return render(request, 'ScopeManagement/index.html', Requirement_dict) 
django.core.exceptions导入ObjectDoesNotExist的
01
02来自ScopeManagement.models导入需求矩阵
03
04
05 def索引(请求):
06#查询数据库以获取特定项目的需求列表。
07#将清单放入我们的需求词典中,该词典将传递给
08#模板引擎。
09
10试试:
11
12需求列表=需求矩阵。对象。所有()从ScopeManagement.models导入需求矩阵
>>>需求矩阵.objects.all()
[]

原因可能是什么?

首先,intellisense对代码的看法完全无关;你应该忽略它。然而,该代码无法引发该异常
.all()
永远不会引发DoesNotExist。当您转到该视图时,您看到的实际错误是什么?谢谢,您是对的。当我调试代码时,我发现它在Requirement_dict字段上,我将其更改为context_dict,然后我可以看到它正在用数据库中的值填充context_dict。首先,intellisense对代码的看法完全无关;你应该忽略它。然而,该代码无法引发该异常
.all()
永远不会引发DoesNotExist。当您转到该视图时,您看到的实际错误是什么?谢谢,您是对的。当我调试代码时,我发现它位于Requirement_dict字段上,我将其更改为context_dict,然后我可以看到它正在用数据库中的值填充context_dict。
python manage.py shell
>>> from ScopeManagement.models import Requirement_Matrix
>>> Requirement_Matrix.objects.all()
[<Requirement_Matrix: Requirement 1>]