我是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')
models.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