问题遇到的现象和发生背景
AttributeError: type object 'Blog' has no attribute 'bojects'
问题相关代码,请勿粘贴截图
from django.db import models
# Create your models here.
# https://blog.csdn.net/qq_37487967/article/details/84248793
class Blog(models.Model):
title = models.CharField(u'标题', max_length=64)
content = models.TextField(u'内容', default="")
update_time = models.DateTimeField(u'更新时间', auto_now=True)
pub_date = models.DateField(u'发布时间')
author = models.CharField(u'作者', max_length=64, default=None)
# update_time.editable = True
# 列表中显示的内容
def __str__(self):
return "标题:{},字数:{},概要:{}".format(self.title, len(self.content), self.content[:18])
#返回多个对象
# django 数据库 mysql
def themes(request):
print("request post params_post")
print(request)
if request.method=='GET':
print( "request", request)
# Blog.save()
# Blog.lis
# Blog.save()
# print( "request.POST", request.POST)
# https://blog.csdn.net/changfcqxhy/article/details/90757305
BlogAll=Blog.bojects.all()#查询所有数据
print("BlogAll",BlogAll)
# AttributeError: type object 'Blog' has no attribute 'bojects'
res={
"code":200,
"data":BlogAll,
"msg":"ok"
}
return JsonResponse(res)
# return render(request,'post.html')
else:
print( "request.POST", request.POST)
username=request.POST.get('username','')
password=request.POST.get('password','')
res={
"code":200,
"data":request.POST,
"msg":"ok"
}
return JsonResponse(res)
运行结果及报错内容
Traceback (most recent call last):
File "D:\software\anaconda\envs\django3\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\software\anaconda\envs\django3\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\proj\python\hello\HelloWorld\HelloWorld\views.py", line 35, in themes
BlogAll=Blog.bojects.all()#查询所有数据
AttributeError: type object 'Blog' has no attribute 'bojects'
(django3) C:\Users\25004>pip list
Package Version
asgiref 3.5.2
certifi 2022.6.15
charset-normalizer 2.1.1
cycler 0.11.0
Django 3.2.15
django-cors-headers 3.13.0
fonttools 4.37.1
idna 3.3
importlib-metadata 4.12.0
kiwisolver 1.4.4
Markdown 3.4.1
matplotlib 3.5.3
numpy 1.21.6
packaging 21.3
pandas 1.3.5
Pillow 9.2.0
pip 22.1.2
PyMySQL 1.0.2
pyparsing 3.0.9
python-dateutil 2.8.2
pytz 2022.2.1
requests 2.28.1
setuptools 63.4.1
six 1.16.0
sqlparse 0.4.2
typing_extensions 4.3.0
urllib3 1.26.12
wheel 0.37.1
wincertstore 0.2
zipp 3.8.1