Jonathan Star 2022-09-09 14:27 采纳率: 74.5%
浏览 38
已结题

AttributeError: type object 'Blog' has no attribute 'bojects'

问题遇到的现象和发生背景

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

完整代码
https://gitee.com/starplatinum111/django_hello
win 10

  • 写回答

1条回答 默认 最新

  • honestman_ 2022-09-09 14:34
    关注

    写错了: 应该是 objects 写成了 bojects

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月17日
  • 已采纳回答 9月9日
  • 修改了问题 9月9日
  • 创建了问题 9月9日

悬赏问题

  • ¥15 如何制作永久二维码,最好是微信也可以扫开的。(相关搜索:管理系统)
  • ¥15 delphi indy cookie 有效期
  • ¥15 labelme打不开怎么办
  • ¥35 按照图片上的两个任务要求,用keil5写出运行代码,并在proteus上仿真成功,🙏
  • ¥15 免费的电脑视频剪辑类软件如何盈利
  • ¥30 MPI读入tif文件并将文件路径分配给各进程时遇到问题
  • ¥15 pycharm中导入模块出错
  • ¥20 Ros2 moveit2 Windows环境配置,有偿,价格可商议。
  • ¥15 有关“完美的代价”问题的代码漏洞
  • ¥15 请帮我看一下这个简易化学配平器的逻辑有什么问题吗?