我的简单Django博客不起作用 - 如果我去http://127.0.0.1:8000/posts/create/我看到了
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/posts/create/
Raised by: posts.views.post_create
查看git历史记录,我了解posts / views.py中的错误。
文件本身看起来像这样
from urllib.parse import quote
from django.shortcuts import render, get_object_or_404, redirect
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.contrib import messages
from .forms import PostForm
from .models import Post
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render
def post_create(request):
if not request.user.is_staff or not request.user.is_superuser:
raise Http404
form = PostForm(request.POST or None, request.FILES or None)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
messages.success(request, 'Successfully Created')
return HttpResponseRedirect(instance.get_absolute_url())
context = {
'form': form,
}
return render(request, 'posts/post_form.html', context)
def post_detail(request, id=None):
instance = get_object_or_404(Post, id=id)
share_string = quote(instance.content)
context = {
'title': instance.title,
'instance': instance,
'share_string': share_string
}
return render(request, 'posts/post_detail.html', context)
def post_list(request):
queryset_list = Post.objects.all()
paginator = Paginator(queryset_list, 5)
page = request.GET.get('page')
queryset = paginator.get_page(page)
context = {
'object_list': queryset,
'title': 'List'
}
return render(request, 'posts/post_list.html', context)
def post_update(request, id=None):
if not request.user.is_staff or not request.user.is_superuser:
raise Http404
instance = get_object_or_404(Post, id=id)
form = PostForm(request.POST or None, request.FILES or None,
instance=instance)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
messages.success(request, '<a href="#">Item</a>Saved',
extra_tags='html_safe')
return HttpResponseRedirect(instance.get_absolute_url())
context = {
'title': instance.title,
'instance': instance,
'form': form
}
return render(request, 'posts/post_form.html', context)
def post_delete(request, id=None):
if not request.user.is_staff or not request.user.is_superuser:
raise Http404
instance = get_object_or_404(Post, id=id)
instance.delete()
messages.success(request, 'Successfully Deleted')
return redirect('posts:list')
我认为if not request.user.is_staff or not request.user.is_superuser
行中的错误
因为在这一行之后,如果我从历史中正确理解,django-blog就无法工作
django.VERSION - (2,0,1,&#39; final&#39;,0)
非常感谢你。