djangoで性格診断サイトのようなものを作りたい

djangoで性格診断のようなシステムを作っています。
例)https://tenshoku.mynavi.jp/opt/society/

modelsでquestionテーブルを作り、viewsでselfdetailクラスを作ったあと、管理画面で「aaa」と入力し、self_detail.htmlを作成しました。
そしてself_detail.htmlに{{ question }}と入力したところ、以下のエラーメッセージが発生しました。

Page not found (404)
クエリーに一致する question は見つかりませんでした
Request Method: GET
Request URL: http://127.0.0.1:8000/self/1/
Raised by: pajamanApp.views.SelfDetail

実現したいこと

なぜquestionの内容が表示されないのかがわからないのでこのエラーを解決したいです;
ちなみにほかのhtmlでもquestionを使用しているのですが、そこでは表示されるため、viewに問題があるのでは…?と踏んでいるのですが初心者のため、よくわからない状態です。

発生している問題・エラーメッセージ

クエリーに一致する question は見つかりませんでした
「models.py」 class Question(models.Model): q_id = models.AutoField(primary_key=True,verbose_name='質問ID') question = models.TextField(verbose_name='質問の内容') class Meta: verbose_name_plural = '質問' def __str__(self): return self.question
「views.py」 class SelfDetail(DetailView): model = Question context_object_name = "question" template_name = "pajamanApp/self_detail.html" def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["anwser"] = Answer.objects.filter(a_id=self.kwargs['pk']) #context['evalution'] = EvaluationForm return context def post(self): if self.request.POST.get('anwser'): return HttpResponseRedirect("/self") anwser = self.request.POST.get('anwser') Self.objects.create(question=self.kwargs['pk'],user=self.request.user,anwser=anwser) if self.kwargs['pk'] == 10: return HttpResponseRedirect("/self") else: return HttpResponseRedirect(f"/self/{self.kwargs['pk']+1}/")
「self_detail.html」 {% extends 'base.html' %} {% block title %}{{ block.super }} テスト {% endblock %} {% block content %} <div class="table"> <h2>あなたの性格についての質問を開始します</h2> {{ question }} <form method="post"> {% csrf_token %} {% for a in anwser %} <!-- <input type="button" name="anwser" value="{{ a }}"> --> <button value="{{ a.id }}">{{ a }}</button> {% endfor %} </form> <!-- <table class="table"> <tbody> <tr> <td>{{ Self_detail }}</td> </tr> <tbody> </table> --> <a href="{% url 'pajamanApp:main' %}">戻る</a> {% endblock %}

補足情報(FW/ツールのバージョンなど)

Python 3.10.7

プログラムも質問の仕方も初心者なため、質問に対する不足部分があれば教えてください。

コメントを投稿

0 コメント