django.urls.exceptions.NoReverseMatch: Reverse for 'exam_result' with keyword arguments '{'result': 20}' not found. 1 pattern(s) tried: ['exams/result/\\Z']

Hi

I’m at the beginner level (python & Django) trying to build a web app(Practice Exam application) and I’m struggling to understand below error. Can someone guide me on this please.

views.py

@login_required
def start_exam(request):

    questions =  Question.objects.all() [:10] # exam.questions.all()
    
    if request.method == "POST":
        form = ExamForm(request.POST, questions = questions)
        if form.is_valid():
            score = 0
            for i, question in enumerate(questions):
                selected_answer =  form.cleaned_data[f"question_{i}"] # request.POST.get(f"question_{question.id}")  #
                if selected_answer == question.correct_answer:
                    score +=1
            # Save the result to the database
            exam_result = ExamResult(user=request.user, score=score, total_questions = len(questions))     
            exam_result.save()
            return redirect("exam_result", result= exam_result.id)
    else:
        
        form = ExamForm(questions=questions)
        return render(request, "exams/start_exam.html", {"form": form})
  

@login_required
def exam_result(request):
    # exam = Exam.objects.get(id=exam_id)
    result = ExamResult.objects.get(user=request.user)
    return render(request, "exams/exam_result.html",{"result": result})

result template

{% extends 'base.html' %}

{% block content %}
  <h2>Exam Result: {{ result.exam.name }}</h2>
  <p>Your Score: {{ result.score }} / {{ result.total_questions}}</p>
 
{% endblock %}

**Start Exam template**
{% extends 'base.html' %}
{% block content %}
	  <h2>Start Exam</h2>
	  <form method="POST">
	    {% csrf_token %}
    
	    {% for question in form %}
	      {{ form.as_p }}
	    {% endfor %}
    
	    <button type="submit">Submit</button>
	  </form>
	{% endblock %}

Error

 [14/Feb/2025 10:56:02] "GET /exams/start/ HTTP/1.1" 200 1598
Internal Server Error: /exams/start/
Traceback (most recent call last):
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/contrib/auth/decorators.py", line 60, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "/Users/Kiran.Thota/Exam-Prep/exam_portal/exams/views.py", line 29, in start_exam
    return redirect("exam_result", result= exam_result.id)
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/shortcuts.py", line 49, in redirect
    return redirect_class(resolve_url(to, *args, **kwargs))
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/shortcuts.py", line 180, in resolve_url
    return reverse(to, args=args, kwargs=kwargs)
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/urls/base.py", line 88, in reverse
    return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
  File "/Users/Kiran.Thota/Exam-Prep/vdjango/lib/python3.10/site-packages/django/urls/resolvers.py", line 831, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'exam_result' with keyword arguments '{'result': 20}' not found. 1 pattern(s) tried: ['exams/result/\\Z']
[14/Feb/2025 10:56:05] "POST /exams/start/ HTTP/1.1" 500 92258
  

URL.py

    path('', auth_views.LoginView.as_view(), name='login'),
    path('logout/', views.logout, name='logout'),
    path("register/", views.register, name="register"),
    path('start/', views.start_exam, name='start_exam'),
    path('result/', views.exam_result, name='exam_result')
]

Side Note: When posting code, templates, error messages, or other preformatted text here, enclose the code between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted. (I have taken the liberty of correcting your original posts.
Please remember to do this in the future.)

Please post the url definition for exam_result. (It might be helpful if you posted the contents of the entire file that it is in.)

Thanks for the response @KenWhitesell , I will ensure to the post code with proper formatting from next time. I have now posted URL.py as well. can you please advice what could be the issue.
Thanks

This url doesn’t take a parameter.

Which makes this invalid.