我试图做一个测验,每个问题将显示在不同的页面上。但是我猜像has_previous和has_next这样的属性不起作用。
views.py
def instructions(request):
ques = Questionm.objects.first()
context = {'ques': ques}
return render(request,'events/instructions.html', context)
def ques_detail(request,pk=Questionm.objects.filter(marks=10).order_by("pk").values().first()):
ques = get_object_or_404(Questionm, pk=pk)
context = {'ques': ques}
paginate_by = 1
return render(request, 'events/ques_detail.html', context)
def ques_detail2(request, pk):
ques = get_object_or_404(Questioni, pk=pk)
context = {'ques': ques}
paginate_by = 1
return render(request, 'events/ques_detail2.html', context)
ques_detail.html
{% block title %}
<div class="round1">
<h1>ROUND-1</h1>
</div>
<div class="ques">
<h2>Q. {{ ques.question }}</h2><br><br><br><br>
<p><input type="checkbox" name="opt1">{{ ques.opt1 }}<br><br>
<input type="checkbox" name="opt2">{{ ques.opt2 }}<br><br>
<input type="checkbox" name="opt3">{{ ques.opt3 }}<br><br>
<input type="checkbox" name="opt4">{{ ques.opt4 }}<br><br></p>
<div class="pagination">
{% if is_paginated %}
{% if ques.has_previous %}
<a class="btn btn-outline-info mb-4" href="?page={{ ques.previous_page_number }}">Previous</a>
{% endif %}
{% for num in ques.paginator.page_range %}
{% if ques.number == num %}
<a class="btn btn-info mb-4" href="?page={{ num }}">{{ num }}</a>
{% endif %}
{% endfor %}
{% if ques.has_next %}
<a class="btn btn-outline-info mb-4" href="?page={{ ques.next_page_number }}">Next</a>
{% endif %}
{% endif %}
</div>
</div>
{% endblock %}
我只能看到问题和四个选项。不是上一个和下一个按钮。 有人帮忙。