“列表”对象上的AttributeError没有属性“对象”

时间:2020-03-31 20:35:15

标签: python django

我正在学习Expr,并遇到以下错误。

“列表”对象上的AttributeError没有属性“对象”

这是我的代码:

Expr
  • 我使用class Exam(models.Model): exam_title = models.CharField(max_length=200) class Question(models.Mode): question_content = models.CharField(max_length=200) exam_id = models.ForeignKey(Exam, on_delete=models.CASCADE) class Option(models.Model): option_question = models.ForeignKey(Question, on_delete=models.CASCADE) is_answer = models.BooleanField(default=False) option_value = models.CharField(max_length=240) # Admin models class OptionInline(admin.TabularInline): model = Option class QuestionInline(admin.TabularInline): model = Question inlines = [OptionInline] class ExamAdmin(admin.ModelAdmin): inlines = [QuestionInline,] Django用数据库创建了一些对象。我使用Models.py from django.db import models from django.utils import timezone from django.contrib.auth.models import User class post(models.Model):` title = models.CharField(max_length = 100) content = models.TextField() date_posted = models.DateTimeField(default = timezone.now) author = models.ForeignKey(User,on_delete = models.CASCADE) def __str__(self): return self.title Views.py : from django.shortcuts import render from .models import post #lets add some dummy data post = [ { 'author':'raj kumar', 'title' :'blog title 1', 'date_posted':'27 August 2020 ', "content" :"fist post content" }, { 'author': "kathir", 'title': 'blog title 2', 'date_posted':"28 August 2020 ", "content" :"second post content" } ] def home(request): context = { "posts": post.objects.all() } return render(request,'blog/home.html',context) def blog(request): return render(request,'blog/blog.html') 类插入了一些数据。
Django

1 个答案:

答案 0 :(得分:0)

您将帖子视为对象。不是。这是词典列表。