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

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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退