###前提・実現したいこと
DjangoGirlsというチュートリアルに従って、PythonのDjangoを使いblogを作成しようとしています。そこで、ブログの投稿ページは作成し、データをデータベースに保存することはできたものの、次の画面に遷移することができずエラーが出てしまいました。
■ 参照ページ
###発生している問題・エラーメッセージ
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/post/21/edit/posts.views.post_detail Using the URLconf defined in blog.urls, Django tried these URL patterns, in this order: ^$ ^post/(?P<pk>[0-9]+)/$ ^post/new/$ [name='post_new'] ^post/(?P<pk>[0-9]+)/edit/$ ^admin/ The current URL, post/21/edit/posts.views.post_detail, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
###該当のソースコード
views.py
def post_edit(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.save() return redirect('posts.views.post_detail', pk=post.pk) else: form = PostForm(instance=post) return render(request, 'posts/post_edit.html', {'form': form})
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/09 08:51
2017/02/09 08:51