默认管理器“Objects”不适用于m

2024-09-27 00:16:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python很陌生&;Django和我正在学习一个教程,但是由于某些原因,我尝试做的一个类似的练习对我不起作用

我正在创建一个简单的views.py和一个简单的类MissingBusiness。 无法识别尝试引用模型类的“对象”默认管理器。 我想使用MissingBusiness.objects.all()从数据库中获取所有记录。
如何使物体被识别

这是我的观点。py

from django.http import HttpResponse     
from django.shortcuts import render    
from .models import MissingBusiness     

def indexRoot (request):    
    BusinessList = MissingBusiness.objects.all()  
    return render(request,'index.html')    

型号.py:

from django.db import models    

class MissingBusiness(models.Model):    
    businessName = models.CharField(max_length=255)    
    category = models.IntegerField()    

似乎由于某些原因无法识别默认管理器“对象”。
获取错误:

AttributeError at /ManageMissingBusinesses/
'function' object has no attribute 'objects'

Request Method:
GET 

Request URL:
http://localhost:59564/ManageMissingBusinesses/ 

Django Version:
2.2.5 

Exception Type:
AttributeError 

Exception Value:
'function' object has no attribute 'objects'

Exception Location:
C:\Python\BankAccountUI\BankAccountUI\ManageMissingBusinesses\views.py in indexRoot, line 7 

Python Executable:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe 

Python Version:
3.6.3 

Python Path:
['C:\\Python\\BankAccountUI\\BankAccountUI',
 'C:\\Python\\BankAccountUI\\BankAccountUI',
 'C:\\Program Files (x86)\\Microsoft Visual '
 'Studio\\Shared\\Python36_64\\python36.zip',
 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\DLLs',
 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64\\lib',
 'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python36_64',
 'C:\\Program Files (x86)\\Microsoft Visual '
 'Studio\\Shared\\Python36_64\\lib\\site-packages']

Server time:
Wed, 9 Oct 2019 19:32:12 +0000

Tags: frompyimportobjectsmodelsfilesprogramx86

热门问题