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

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日

悬赏问题

  • ¥20 Hbase启动失败,无法启动HMaster
  • ¥15 sqpingboot在父模块已经引入了mybatisplus 在子组件不写版本号还是报错
  • ¥20 Lumerical FDTD solutions 中模型的相对阻抗,有效介电常数和有效磁导率的实部和虚部的数据如何获得?
  • ¥100 sql reporting service 远程smtp服务器配置支持
  • ¥15 ppyoloe_r带角度目标检测,loss_cls没法收敛
  • ¥15 淘宝交易指数如何解读,其关联的数据指标是什么
  • ¥15 Linux下安装搜狗拼音不能显示中文
  • ¥15 事件7000导致的自动重启如何解决
  • ¥15 (标签-matlab|关键词-m3)
  • ¥20 做一个web书店,带答辩