Код из
views.py from django.shortcuts import render
from django.http import HttpResponse,Http404
from .models import Question,Answer
def polls(request):
all_question = Question.objects.all()
context = {"all_question" : all_question}
return render(request,"Question&Answer/index.html", context)
def question(request,question_id):
try:
answer = Answer.objects.get(foreign_field_id=question_id)
except Answer.DoesNotExist:
raise Http404("Answer Not Found")
return render(request, "Question&Answer/detail.html",{"answer": answer})