I wanted to have a comment section in the same page as in my DetailView so I decided to use the FormMixin as a way to be able to add comments. It's not raising any errors but the submitted comments seem to be going nowhere and it's not showing up in the admin site also.
models.py
from django.db import models
from django.utils import timezone
from django.urls import reverse
from embed_video.fields import EmbedVideoField
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField(max_length = 100)
content = models.TextField()
video = EmbedVideoField()
date_posted = models.DateTimeField(default = timezone.now)
author = models.ForeignKey(User, on_delete = models.CASCADE)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})
class PostComment(models.Model):
post = models.ForeignKey(Post, related_name='comments', on_delete = models.CASCADE)
author = models.ForeignKey(User, on_delete = models.CASCADE)
date_posted = models.DateTimeField(default = timezone.now)
body = models.TextField()
def __str__(self):
return f'{self.post} - {self.author}'
forms.py
from django import forms
from django.forms import ModelForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Fieldset, Button, Layout, Div, ButtonHolder, Field, Reset
from .models import Post, PostComment
from crispy_forms.bootstrap import FormActions
from django.urls import reverse
class CommentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.fields['body'].required = True
self.fields['body'].label = False
self.helper.layout = Layout(
Field('body', style='max-height: 90px', placeholder='Write a comment...'),
ButtonHolder(
Submit('submit', 'Post', css_class='m-2 ms-3'),
Reset('Reset This Form', 'Cancel', css_class='btn btn-secondary')
),
)
class Meta:
model = PostComment
fields = ['body','post',]
views.py
I mostly got this from the django documentations.
from django.shortcuts import render
from django.views.generic import (
ListView,
DetailView,
CreateView,
UpdateView,
DeleteView
)
from .models import Post, PostComment
from .forms import PostCreateForm, CommentForm
from django.views.generic.edit import FormMixin
class PostDetailView(FormMixin, DetailView):
model = Post
context_object_name = 'posts'
form_class = CommentForm
def get_success_url(self):
return reverse('post-detail', kwargs={'pk': self.object.id})
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['form'] = CommentForm(initial={'post': self.object})
return context
def post(self, request, *args, **kwargs):
self.object = self.get_object()
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)
def form_valid(self, form):
form.save()
return super(PostDetailView, self).form_valid(form)
urls.py
urlpatterns = [
path('', PostListView.as_view(), name = 'home-home'),
path('post/new/', PostCreateView.as_view(), name = 'post-create'),
path('post/<int:pk>/', PostDetailView.as_view(), name = 'post-detail'),
]
post_detail.html
{% extends 'videosite/base.html' %}
{% load crispy_forms_tags %}
{% load embed_video_tags %}
{% block body %}
<div class="container mt-5">
<div class="card border-dark">
<div class="row row-cols-2 gutter-0">
<div class="col-7 pe-0" style="height: 526px;">
<div class="card-body border-end border-dark">
<div class="embed-responsive embed-responsive-16by9">
{% video posts.video '720x490' %}
</div>
</div>
</div>
<div class="col-5 ps-0" style="height: 526px;">
<div class="card-body bg-light" style="height: 526px;">
{% for comment in posts.comments.all %}
<a class="h5 text-dark text-decoration-none me-5" href="#"> {{ comment.author }}</a>
<span class="ms-3" >{{ comment.date_posted|date:"F d, Y" }}</span>
<p class="card-text">{{ comment.body }} </p>
{% endfor %}
</div>
{% csrf_token %}
{% crispy form %}
</div>
<div class="col-7 pe-0" >
<div class="card-body border-top border-end border-dark">
<h5><a class="fw-bold text-dark text-decoration-none" href="#">{{ posts.title }}</a></h5>
<p class="card-text">{{ posts.content }}</p>
</div>
<div class="card-body border-end border-dark" >
<span class="text-muted text-decoration-none">Posted by <a class="text-muted" href="#"> {{ posts.author }}</a> </span>
<span class="ms-3 text-muted" >{{ posts.date_posted|date:"F d, Y" }}</span>
</div>
</div>
</div>
</div>
</div>
{% endblock body %}
Use FormView not DetailView as your base class. I expect it'll all then work.
An invaluable resource is Classy Class-based views. It shows that DetailView does not have a POST handler (method) and that FormMixin does not provide that either, which is probably why what you have is not working.
POST handling is defined by FormView itself.
Related
I copied this code from maxg203 https://github.com/maxg203/Django-Tutorials
I had another errors but I managed to solve them but when it came to this one I stayed for a solid 4 hours trying to solve it and until now I didn't manage to
I am still a beginner in Django
My Models.py:
from django.db import models
from django.contrib.auth.models import User
class Post(models.Model):
post = models.CharField(max_length=500)
user = models.ForeignKey(User, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Friend(models.Model):
users = models.ManyToManyField(User)
current_user = models.ForeignKey(User, related_name='owner', null=True, on_delete=models.CASCADE)
#classmethod
def make_friend(cls, current_user, new_friend):
friend, created = cls.objects.get_or_create(
current_user=current_user
)
friend.users.add(new_friend)
#classmethod
def lose_friend(cls, current_user, new_friend):
friend, created = cls.objects.get_or_create(
current_user=current_user
)
friend.users.remove(new_friend)
my Views.py:
from django.views.generic import TemplateView
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from home.forms import HomeForm
from home.models import Post, Friend
class HomeView(TemplateView):
template_name = 'home/home.html'
def get(self, request):
form = HomeForm()
posts = Post.objects.all().order_by('-created')
users = User.objects.exclude(id=request.user.id)
friend = Friend.objects.filter(current_user=request.user)
friends = friend.users.all()
args = {
'form': form, 'posts': posts, 'users': users, 'friends': friends
}
return render(request, self.template_name, args)
def post(self, request):
form = HomeForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.user = request.user
post.save()
text = form.cleaned_data['post']
form = HomeForm()
return redirect('home:home')
args = {'form': form, 'text': text}
return render(request, self.template_name, args)
def change_friends(request, operation, pk):
friend = User.objects.get(pk=pk)
if operation == 'add':
Friend.make_friend(request.user, friend)
elif operation == 'remove':
Friend.lose_friend(request.user, friend)
return redirect('home:home')
My Forms.py
from django import forms
from home.models import Post
class HomeForm(forms.ModelForm):
post = forms.CharField(widget=forms.TextInput(
attrs={
'class': 'form-control',
'placeholder': 'Write a post...'
}
))
class Meta:
model = Post
fields = ('post',)
My urls.py
from django.conf.urls import url
from home.views import HomeView
from . import views
urlpatterns = [
url('', views.HomeView.as_view(), name='home'),
url('connect/(?P<operation>.+)/(P<pk>\d+)/', views.change_friends, name='change_friends')
]
My Html:
{% extends 'base.html' %}
{% block content %}
<div class="container">
<div class="col-md-8">
<h2>Home</h2>
<form method="post">
{% csrf_token %}
{{ form.post }}
<br>
<button type="submit">Submit</button>
</form>
<h2>{{ text }}</h2>
{% for post in posts %}
<h1>{{ post.post }}</h1>
<p>Posted by {{ post.user.get_full_name }} on {{ post.created }}</p>
{% endfor %}
</div>
<div class="col-md-4">
<h2>Other People</h2>
{% for user in users %}
<a href="{% url 'accounts:view_profile_with_pk' pk=user.pk %}">
<h3>{{ user.username }}</h3>
</a>
{% if not user in friends %}
<a href="{% url 'home:change_friends' operation='add' pk=user.pk %}">
<button type="button" class="btn btn-success">Add Friend</button>
</a>
{% endif %}
{% endfor %}
<h2>Friends</h2>
{% for friend in friends %}
<a href="{% url 'accounts:view_profile_with_pk' pk=friend.pk %}">
<h3>{{ friend.username }}</h3>
</a>
<a href="{% url 'home:change_friends' operation='remove' pk=friend.pk %}">
<button type="button" class="btn btn-default">Remove Friend</button>
</a>
{% endfor %}
</div>
</div>
{% endblock %}
Traceback:
Traceback (most recent call last):
File "C:\Users\daghe\anaconda3\envs\env\lib\site-packages\django\core\handlers\exception.py", line 47,
in inner
response = get_response(request)
File "C:\Users\daghe\anaconda3\envs\env\lib\site-packages\django\core\handlers\base.py", line 179, in
_get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
TypeError: __init__() takes 1 positional argument but 2 were given
[30/Sep/2020 16:45:25] "GET / HTTP/1.1" 500 60123
i am getting TypeError at /
init() takes 1 positional argument but 2 were given
Finally, I solved it by putting _as.view in my project's home URL
I’m making a blog site. And I have been trying to render from a model, RecentPosts, objects rpost1, etc. in my template blogs -file base.html which is my blog's details page.
But it is not rendering. Is there a solution?
File views.py
from django.http import HttpResponse
from django.shortcuts import render
from blog.models import Post
from django.contrib import messages
from django.views.generic import ListView, DetailView
from .models import Post, RecentPosts, Comment, Contact, Populars
from datetime import datetime
from .forms import CommentForm
def index(request):
return render(request, 'index.html')
def path(request):
return render(request, 'blog.html')
def cv(request):
return render(request, 'cv.html')
class HomeView(ListView):
model = Post
template_name = 'listview.html'
class ArticleDetailView(DetailView):
model = Post
template_name = 'base2.html'
def rpost(request):
template_name = "blogs-base.html"
rpost = RecentPosts.objects.all()
context = {'rpost': 'rpost'}
return render(request, template_name, context)
This is the URL portion.
File urls.py
from django.urls import path
from . import views
from .views import HomeView, ArticleDetailView, contact, Comment_page, popular
urlpatterns = [
path('', views.index, name='index'),
path('index.html', views.index, name='index'),
path('cv.html', views.cv, name='cv'),
path('blogs/', views.HomeView.as_view(), name="blogs"),
path('blogs/<slug:slug>', ArticleDetailView.as_view(), name='base2'),
path('contact/', views.contact, name='contact'),
path('contact.html/', views.contact, name='contact'),
path('comment.html/', views.Comment_page, name='comment'),
path('popular', views.popular, name='popular'),
]
This is the model portion.
File models.py
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from django.utils.timezone import now
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=120)
author_name = models.CharField(max_length=120)
author_description = models.CharField(max_length=120)
body = models.TextField(default='')
slug = models.CharField(max_length = 130)
timestamp = models.DateTimeField(auto_now=True)
def get_abosolute_url(self):
return reverse()
class Comment(models.Model):
post = models.ForeignKey('Post', on_delete=models.CASCADE, related_name='comments')
user = models.CharField(max_length=200)
message = models.TextField()
timestamp = models.DateTimeField(auto_now=True)
def __str__(self):
return self.user.capitalize() + ' : ' + self.message[0:16] + '........'
class Contact(models.Model):
email = models.CharField(max_length=20)
message = models.CharField(max_length=200)
models.CharField(max_length=200)
class RecentPosts(models.Model):
rpost1 = models.CharField(max_length=120)
rpost2 = models.CharField(max_length=120)
rpost3 = models.CharField(max_length=120
)
File blogs-base.html
<a href="marketing-single.html" class="list-group-item list-group-item-action flex-column align-items-start">
<div class="w-100 justify-content-between">
<img src="assets/blog-uploads/ad.png" alt="" class="img-fluid float-left">
{% for i in rpost %} <h5 class="mb1">{{i.rpost1}}</h5>
<small>12 Jan, 2016</small>{% endfor %}
</div>
</a>
This is the listview where I’m posting only my blog's thumbnails.
File listview.html
{% extends 'blogs-base.html' %}
{% load static %}
{% block title %}{{post.title}}{% endblock %}
{% block content %}
{% for post in object_list %}
<div class="col-lg-6">
<div class="blog-box">
<div class="post-media">
<a href="marketing-single.html" title="">
<img src="{% static 'website/assets/blog-uploads/ad.png' %}" alt="" class="img-fluid">
<div class="hovereffect">
<span class=""></span>
</div><!-- end hover -->
</a>
</div><!-- end media -->
<div class="blog-meta">
<h4>{{post.title}}</h4>
<small></small>
<small>20 July, 2017</small><br><br>
</div><!-- end meta -->
</div><!-- end blog-box -->
</div><!-- end col -->
{% endfor %}
{% endblock %}
You made a mistake in your context. You're are passing a string of 'rpost' instead of
context = { "rpost" : rpost }
This is for a library management web app, I need to filter a specific book object by it's id from a BookIssue object and make it as ISSUED when I click on issue button.
Here Post model have details of book and BookIssue have details of Library Member to borrow book.
When I click on Issue in html, it will go class BookIssueView, fromviews.py I need to change the value of issued field of Post model to True
See post = Post.objects.filter(id=self.request.GET.get('id')).update(issued=True) in views.py
Here I need to get the specific book that I selected by it's id.
How can I implement it?
models.py
class Post(models.Model):
title = models.CharField(max_length=100)
book_author = models.CharField(default="",max_length=100)
publisher = models.CharField(default="",max_length=100)
content = models.TextField(max_length=200)
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
issued = models.BooleanField(default=False)
issued_to = models.CharField(default="",max_length=100,null=False)
issue_to_phone_number = models.CharField(default="",max_length=10)
def __str__(self):
return [self.title,self.id]
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk' : self.pk})
class BookIssue(models.Model):
issue_name = models.CharField(max_length=100,null=False)
issue_email = models.EmailField(max_length=254)
issue_phone_number = models.CharField(default="",max_length=10)
issue_address = models.TextField(max_length=300)
issued_book = models.ManyToManyField(Post,default="")
def __str__(self):
return self.issue_name
def get_absolute_url(self):
return reverse('blog-home')
views.py
class BookIssueView(LoginRequiredMixin,CreateView,Post):
model = BookIssue
fields = ['issue_name','issue_email','issue_phone_number','issue_address']
def form_valid(self, form):
post = Post.objects.filter(id=self.request.GET.get('id')).update(issued=True)
form.instance.author = self.request.user
return super().form_valid(form)
Template
bookissue_form.html
{% extends "blog/base.html" %}
{% load crispy_forms_tags %}
{% block content %}
<div class="content-section">
<form method="post">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Issue Book</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-success" type="submit" name="button">Issue</button>
<button class="btn btn-danger" type="submit" name="button">Cancel</button>
</div>
</form>
</div>
{% endblock %}
urls.py
from django.urls import path
from . import views
from .views import (PostListView,
PostDetailView,
PostCreateView,
PostUpdateView,
PostDeleteView,
BookIssueView,
BookReturnView)
urlpatterns = [
# path('',views.home, name='blog-home'),
path('',PostListView.as_view(), name='blog-home'),
path('post/<int:pk>/',PostDetailView.as_view(), name='post-detail'),
path('post/new/',PostCreateView.as_view(), name='post-create'),
path('post/<int:pk>/update/',PostUpdateView.as_view(), name='post-update'),
path('post/<int:pk>/delete/',PostDeleteView.as_view(), name='post-delete'),
path('post/<int:pk>/issue/',BookIssueView.as_view(), name='book-issue'),
path('post/<int:pk>/return/',BookReturnView.as_view(), name='book-return'),
path('about/',views.about, name='blog-about'),
]
The id is not in request.GET, it is in the pk kwarg of the URL.
Also, you don't seem to be doing anything to associate the Post with the BookIssue.
post = Post.objects.get(id=self.kwargs["pk"])
post.issued=True
post.save()
response = super().form_valid(form)
form.instance.issued_book.add(post)
return response
am using django 2.0 and here is the problem
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/blog/post-detail/
Raised by: blog.views.post_detail
No Post matches the given query.
here is the blog/urls
from django.urls import path,include
from .import views
urlpatterns = [
path('blog/',views.post_list,name="post_list"),
path('blog/post-detail/',views.post_detail,name="post_detail"),
]
and views.py
from django.shortcuts import render,get_object_or_404
from.models import Post
# Create your views here.
def post_list(request):
object_list=Post.objects.all()
context={
'object_list': object_list,
}
return render(request,"blog.html",context)
def post_detail(request,slug=None):
post=get_object_or_404(Post,slug=slug)
context={
'post':post,
}
return render(request,"post_detail.html",context)
and the post_detail.html
{% extends "base.html" %}
{% load static %}
{% block seo_title %}{% endblock %}
{% block seo_description %}{% endblock %}
{% block Content %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">
<h2>{{post.title}}</h2>
<div>
{{post.created}} Author {{Post.user}}
<hr/>
<p>{{post.body}}</p>
</article>
{% endblock Content %}
CAN ANYONE HELP ON THIS THE ONLY PROBLEM I SEE THAT SLUG THING I MUST HAVE CONFUSED SOMEWHERE
blog.html
<!-- Blog -->
<div class="blog">
<div class="row">
<div class="col-sm-8">
<!-- Blog Post-->
{% for obj in object_list %}
{% if obj.status == 'Published' %}
<article>
<div class="embed-responsive embed-responsive-16by9">
<img src="images/blog1.jpg" alt="" />
</div>
<div class="post-content">
<h2>{{obj.title}}</h2>
<div>
{{obj.created}} Author {{obj.user}}
<hr/>
<p>{{obj.body}}</p>
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' slug= post.slug %}">Continue reading →</a><br>
</div>
</article>
{% endif %}
{% endfor %}
The view post_detail(request,slug=None) is to view details about a post. So your URL pattern is incorrect:
path('blog/post-detail/<slug:slug>',views.post_detail,name="post_detail"),
To call it in templates, the simpler and correct way to do is:
<a class="mtr-btn button-navy ripple" href= "{% url 'post_detail' obj.slug %}">Continue reading →</a><br>
</div>
#FOLLOW THIS PROCEDURE.I HOPE IT HELPS YOU OR ANY ONE ELSE IN THE FUTURE
# At blog/urls.py
from django.urls import path
from .views import (post_list, post_detail)
urlspatterns = [
path('blog/', post_list, name='post-list'),
path('<str:slug>/blog/post-detail/', post_detail, name='post-detail'),
]
#At blog/views.py
from django.shortcuts import render, get_object_or_404
from .models import Post
def post_list(request):
posts = Post.objects.all()
template_name = blog/post_list.html
context = {'posts':posts}
return render(request, template_name, context)
def post_detail(request, slug):
posts = get_object_or_404(Post, slug=slug)
template_name = blog/post_detail.html
context = {'posts':posts}
return render(request, template_name, context)
# At the template/blog/post_list.html
{% block content %}
{% for post in posts %}
<article>
<div>
<small>{{ post.created_on|date:"F d, Y" }}</small>
<h2>{{ post.title }}</h2>
<p >{{ post.body }}</p>
</div>
</article>
{% endfor %}
{% endblock content %}
# At template/blog/post_detail.html
<article>
<div>
<small>{{ posts.created_on|date:"F d, Y" }}</small>
<h2>{{ posts.title }}</h2>
<p>{{ posts.body }}</p>
</div>
</article>
#The above code should fix the the issue properly.
If your a following Django 3 By Example Book can check this soltuion because I had the same problem.
Book teach how to create Post with a slug attribute with
models.SlugField and unique_for_date='pusblish' condition.
Then you add some posts from admin site.
Then you add some posts from admin site but then in admin.py book teach how to edit the register with
prepopulated_fields = {'sulg':('title',)}.
Finally, book teach you how to edit posts.
This is a problem because never
going to find a post created. So, the solution for me was delete
posts and the create new ones.
here my code:
models.py
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset().filter(status='published')
class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(User,
on_delete=models.CASCADE,
related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')
objects = models.Manager() # The default manager.
published = PublishedManager() # Our custom manager.
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('blog:post_detail',
args=[self.publish.year,
self.publish.month,
self.publish.day, self.slug])
admin.py
from django.contrib import admin
from .models import Post
#admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'slug', 'author', 'publish', 'status')
list_filter = ('status', 'created', 'publish', 'author')
search_fields = ('title', 'body')
prepopulated_fields = {'slug': ('title',)}
raw_id_fields = ('author',)
date_hierarchy = 'publish'
ordering = ('status', 'publish')
views.py
from django.shortcuts import render, get_object_or_404
# another views...
def post_detail(request, year, month, day, post):
post = get_object_or_404(Post, slug=post,
status='published',
publish__year=year,
publish__month=month,
publish__day=day)
return render(request,
'blog/post/detail.html',
{'post': post})
blog/urls.py
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
# post views
path('', views.PostListView.as_view(), name='post_list'),
path('<int:year>/<int:month>/<int:day>/<slug:post>/',
views.post_detail,
name='post_detail'),
]
my_site/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('blog/', include('blog.urls', namespace='blog')),
]
I am to write simple Django blog application.
Django Version: 2.0.4
http://dpaste.com/0H62TQY - this is error output. ( I hope it's safe to show this file all over the Internet =) )
models.py look like
from django.db import models
from django.shortcuts import reverse
from django.template.defaultfilters import slugify
from django.utils import timezone
class Blog(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.PROTECT)
title = models.CharField(max_length=500)
body = models.TextField()
created_at = models.DateTimeField(default=timezone.now)
slug = models.SlugField(default='', editable=False, unique=True, blank=False, null=False)
class Meta:
verbose_name_plural = "blog"
def __str__(self):
return self.title
def get_absolute_url(self):
kwargs = {'slug': self.slug}
return reverse('blog_detail', kwargs=kwargs)
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super().save(*args, **kwargs)
views.pylook like
from django.views.generic import DetailView, ListView
from .models import Blog
class HomeView(ListView):
template_name = 'blog/blog.html'
queryset = Blog.objects.order_by('-created_at')
class BlogDetail(DetailView):
model = Blog
template_name = 'blog/blog-detail.html'
urls.py look like
from django.urls import path, re_path
from . import views
urlpatterns = [
path(r'', views.HomeView.as_view(), name='home'),
re_path(r'^(?P<slug>[-\w]*)/$', views.BlogDetail.as_view(), name='blog_detail'),
]
This is my blog.html
{% for blog in blog_list %}
<div class="item-blog-txt p-t-33">
<h4 class="p-b-11">
<a class="m-text24" href="{{ blog.get_absolute_url }}">
{{ blog.title }}
</a>
</h4>
<div class="s-text8 flex-w flex-m p-b-21">
<span>
{{ blog.author }}
<span class="m-l-3 m-r-6">|</span>
</span>
</div>
<p class="p-b-12">
{{ blog.body|linebreaksbr }}
</p>
<a class="s-text20" href="{{ blog.get_absolute_url }}">
Continue Reading
<i aria-hidden="true" class="fa fa-long-arrow-right m-l-8"></i>
</a>
</div>
{% endfor %}
blog-detail.html look like <a href="{{ blog.get_absolute_url }}"> and {{ blog.title }} and can say everything.
If you need something else to show, email me.
makemigrations and migrate was made.
Thank you very much.
It was the problem in database.
It was a new project so I could also just delete and start a new database.