python - Post matching query does not exist. - Django error while trying to access URL of other pages
问题描述
Everything was okay till I created a blog app in my Django projects, now when I try to access the other apps(pages) on the website, it gives me this error. I can't access the URLs under the other apps, I can only access the URLs under the blog
blog/views.py
from django.shortcuts import render, redirect
from .models import Post
from .forms import commentform
def blog(request):
posts = Post.objects.all(pk=id)
return render(request, 'blog.html', {'posts': posts})
def howtouse(request):
return render(request, 'howtouse.html')
def full_post(request, slug):
post = Post.objects.get(slug=slug)
if request.method == 'POST':
form = commentform(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.save()
return redirect('full_post', slug=post.slug)
else:
form = commentform()
return render(request, 'full_post.html', {'post': post, 'form': form})
blog/models.py
from django.db import models
class Post(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField()
intro = models.TextField()
body = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['-date_added']
class Comments(models.Model):
post = models.ForeignKey(Post, related_name='comments', on_delete=models.CASCADE)
name = models.CharField(max_length=100)
email = models.EmailField()
body = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['date_added']
解决方案
推荐阅读
- java - 带有聚合的 MongoDB 本机查询以在 Java 中查询
- ios - 如何在等待 CoreData/网络请求的状态恢复期间呈现加载微调器?
- java - 如何获取 ListView 中的下一个项目?
- ios - iOS 没有显示丰富的通知
- python - 在硒中找不到元素。XPath,css 选择器,我什么都试过了
- r - 循环中的控制台输出:如何在不添加换行符的情况下完全清除最后一个 cat 输出?
- python - 将 netmiko 与 django 一起使用时导入错误:没有名为 '_cffi_backend' 的模块
- uwp - 如何在 uwp 应用程序中获取系统信息?
- django - 如果在 DeleteView 删除调用期间发生错误,请不要重定向但在 confirm_delete 模板上显示错误
- sql - 用于通过相应行的最小日期时间过滤列的重复行的 SQL 查询