I keep getting this error message "NoReverseMatch at /student/take-exam/1
Reverse for 'emotion-buttons' with arguments '(1,)' not found. 1 pattern(s) tried: ['student/emotion\-buttons$']'".
I have been unable to figure out the problem with my code. When I link take_exam to start_exam it works fine, so the problem should be in linking emotion_buttons to start_exam.
Here is what I have so far:
urls.py
from django.urls import path
from student import views
from django.contrib.auth.views import LoginView
urlpatterns = [
path('student-exam', views.student_exam_view,name='student-exam'),
path('take-exam/<int:pk>', views.take_exam_view,name='take-exam'),
path('emotion-buttons', views.emotion_buttons_view,name='emotion-buttons'),
path('start-exam/<int:pk>', views.start_exam_view,name='start-exam'),
]
views.py
@login_required(login_url='studentlogin')
@user_passes_test(is_student)
def take_exam_view(request,pk):
course=QMODEL.Course.objects.get(id=pk)
total_questions=QMODEL.Question.objects.all().filter(course=course).count()
questions=QMODEL.Question.objects.all().filter(course=course)
total_marks=0
for q in questions:
total_marks=total_marks + q.marks
return render(request,'student/take_exam.html',{'course':course,'total_questions':total_questions,'total_marks':total_marks})
@login_required(login_url='studentlogin')
@user_passes_test(is_student)
def start_exam_view(request,pk):
course=QMODEL.Course.objects.get(id=pk)
questions=QMODEL.Question.objects.all().filter(course=course)
if request.method=='POST':
pass
response= render(request,'student/start_exam.html',{'course':course,'questions':questions})
response.set_cookie('course_id',course.id)
return response
@login_required(login_url='studentlogin')
@user_passes_test(is_student)
def emotion_buttons_view(request):
courses=QMODEL.Course.objects.all()
return render(request,'student/emotion_buttons.html',{'courses':courses})
take_exam.html
<a href="{% url 'emotion-buttons' course.id %}" class="btn btn-info">Let's Start</a>
emotion_buttons.html
<a href="{% url 'start-exam' %}" class="btn btn-info">End Session</a>
Any help would be appreciated