LoginSignup
0
0

More than 1 year has passed since last update.

【Djangoチュートリアル】Page not found (404)とValueError at /polls/1/vote/

Last updated at Posted at 2022-12-09

概要

  • Django チュートリアル04実施中に以下二つのエラーが発生した。無事に解決できたので、備忘録としてここに残しておく。

エラー1の内容 Page not found (404)

Page not found (404)
Request Method:	GET
Request URL:	http://127.0.0.1:8000/
  • 詳細(スクショ)
    スクリーンショット 2022-12-09 11.17.37.png

エラー1の原因・解決方法

  • URLconfに設定したのが「/polls」 又は「/admin」 だけだったので、これらでないとアクセスができませんよ、と言われている。なので、以下URLであればアクセスできる。http://127.0.0.1:8000がダメって言われると「なんでや!?」と慌てがちですが、冷静にurls.pyのurlpatternsを見ないとですね。
  • http://127.0.0.1:8000/polls/
  • http://127.0.0.1:8000/admin/

エラー2の内容 ValueError at /polls/1/vote/

ValueError at /polls/1/vote/
The view polls.views.vote didn't return an HttpResponse object. It returned None instead.
  • 詳細(スクショ)
    スクリーンショット 2022-12-09 11.18.04.png

エラー2の原因・解決方法

  • voteがHttpResponseを返していないというので、polls/view.pyのvote関数を見たら、
polls/view.py
def vote(request, question_id):
    ... # same as above, no changes needed.

となっていた。あら、チュートリアル04からそのままコピペしたから大丈夫だろうと思っていたら、コメントアウトでここは変えるなとあった。ちゃんと読まないとダメですね汗
以前のものに戻してあげたら解決しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0