-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
AttributeError: type object 'Post' has no attribute 'object' 에러
20.07.23 08:49 작성 조회수 2.97k
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)
답변을 작성해보세요.
0
0
0
임찬주
질문자2020.07.23
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
답변 4