当我通过“python manage.py runserver”在django本地服务器中运行我的代码时,一切正常,但是当我在pythonanywhere服务器中运行它时,我得到NoReverseMatch错误。我正在使用git并从那里提取所有代码,但我检查了所有代码,它与我的计算机中的工作正常相同。有人可以说出了什么问题吗?感谢
NoReverseMatch at /
Reverse for 'post_create' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
views.py
from django.shortcuts import render, get_object_or_404,redirect
from django.utils import timezone
from .models import Post
from .forms import PostForm
# Create your views here.
def post_list(request):
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')
return render(request, 'blog/post_list.html', {'posts': posts})
def post_detail(request,pk):
post = get_object_or_404(Post,pk=pk)
return render(request, 'blog/post_detail.html', {'post': post})
def post_create(request):
if request.method == 'POST':
forms = PostForm(request.POST)
if forms.is_valid():
post = forms.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('post_detail',pk = post.pk)
else:
forms = PostForm()
context = {'forms': forms}
return render(request, 'blog/post_create.html',context)
def post_edit(request,pk):
post = get_object_or_404(Post,pk=pk)
if request.method == 'POST':
forms = PostForm(request.POST,instance = post)
if forms.is_valid():
post = forms.save(commit=False)
post.author = request.user
post.published_date = timezone.now()
post.save()
return redirect('post_detail',pk = post.pk)
else:
forms = PostForm(instance=post)
context = {'forms': forms}
return render(request, 'blog/post_create.html',context)
博客/ urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
url(r'^post/new/$', views.post_create, name='post_create'),
url(r'^post/(?P<pk>[0-9]+)/edit/$', views.post_edit, name='post_edit'),
]
mysite的/ urls.py
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'',include('blog.urls'))
]