Inflearn brand logo image

Inflearn Community Q&A

laugh153211346's profile image
laugh153211346

asked

Introduction to Web Development for Python Users A to Z Django + Bootstrap

AttributeError: type object 'Post' has no attribute 'object' 에러

Written on

·

3.3K

0

MTV 구조 맛보기: model, views, templates 사용하기 - 수강 중입니다.

블로그 페이지 만들고 html이랑  urls.py 연동하는 과정에서 저런 에러가 생겼는데 어떻게 해야 할까요?

대충 읽어보니까 models.py에서 object = ??? 를 추가해야 하는 것 같은데 정확히 뭘 추가해야 할까요?

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog</title>
</head>
<body>
<h1>Blog</h1>

{% for p in posts %}
<h3>{{ p }}</h3>
{% endfor %}
</body>
</html>

models.py

from django.db import models
from django.contrib.auth.models import User
# Create your models here.

class Post(models.Model):
title = models.CharField(max_length=30)
content = models.TextField()
created = models.DateTimeField()
author = models.ForeignKey(User, on_delete=models.CASCADE)

def __str__(self):
return '{} :: {}'.format(self.title, self.author)
djangobootstrappython

Answer 4

0

laugh153211346님의 프로필 이미지
laugh153211346
Questioner

해결했슴다! 감사해요

0

sungyonglee님의 프로필 이미지
sungyonglee
Instructor

 Post.object가 아니라 objects 아닐까요??

0

laugh153211346님의 프로필 이미지
laugh153211346
Questioner

views.py 입니다

from django.shortcuts import render
from .models import Post

# Create your views here.

def index(request):
posts = Post.object.all()

return render(
request,
'blog/index.html',
{
'posts': posts,
}
)

0

sungyonglee님의 프로필 이미지
sungyonglee
Instructor

views.py도 보여주시면 감사하겠습니다 

laugh153211346's profile image
laugh153211346

asked

Ask a question