Добрый день, создаю небольшой блог. Использую CBV. При переходе на pk(127.0.0.1:8000/detail/1/) возникает ошибка No post found matching the query, хотя посты имеются в БД. В чем моя ошибка?
models.py
class Post(models.Model):
theme = models.CharField(max_length=100)
post_text = models.CharField(max_length=4000)
pub_date = models.DateTimeField('date published')
def get_absolute_url(self):
return reverse("Blog:index", kwargs={'pk': self.pk}) # реверс - работает без пк kwargs={'pk': self.pk}
def __str__(self):
return self.theme
def was_published_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.self_description = 'Published recently?'
urls.py
app_name = 'Blog'
urlpatterns = [
path('detail/', views.IndexView.as_view(), name='index'),
path('create/', views.CreateView.as_view(), name='create'),
path('detail/<int:pk>/', views.DetailView.as_view(), name='detail'),
]
views.py
class IndexView(generic.ListView):
queryset = Post.objects.all()
template_name = 'Blog/index.html'
context_object_name = 'latest_post_list'
class DetailView(generic.DetailView):
template_name = "Blog/detail_post.html"
#context_object_name = 'Post'
queryset = Post.objects.all()
class CreateView(generic.CreateView):
model = Post
template_name = 'create_post.html'
fields = ['theme',
'post_text',
'pub_date']