# NoReverseMatch error

**URL:** <https://forum.djangoproject.com/t/noreversematch-error/11232>\
**Category:** Using Django\
**Created:** [December 26, 2021, 5:35pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232 "2021-12-26T17:35:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 5:35pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/1 "2021-12-26T17:35:56Z")

</div>

any one who can briefly tell me about NoReverseMatch error with example please?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 6:27pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/2 "2021-12-26T18:27:42Z")

</div>

Start with [django.urls utility functions | Django documentation | Django](https://docs.djangoproject.com/en/4.0/ref/urlresolvers/#module-django.urls).

If you’ve got a specific question or issue, please post the details and we’ll try to resolve it here.

If this is a continuation of [NoReverseMatch at/](https://forum.djangoproject.com/t/noreversematch-at/11177), please do not repost the same issue - continue the discussion there.

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 7:13pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/3 "2021-12-26T19:13:09Z")

</div>

i got some specific problem i have a view that used to save the quiz form like this

```auto
def NewQuiz(request, course_id,module_id):
	user = request.user
	module = get_object_or_404(Module, id=module_id)
	if request.method == 'POST':
		form = NewQuizForm(request.POST)
		if form.is_valid():
			a = Quizzes()
			quiz = NewQuizForm.save(commit=False)
			quiz.module=module
			quiz.save() 
			module.save()
			return redirect('new-question', course_id=course_id, quiz_id=quiz_id)  

			#course=models.Course.objects.get(id=request.POST.get('course_id'))
           
	else:
		form = NewQuizForm()

	context = {
		'form': form,
	}
	return render(request, 'quiz/newquiz.html', context)

```

and the error is "save() missing 1 required positional argument: ‘self’ "

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 7:14pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/4 "2021-12-26T19:14:15Z")

</div>

Please provide the full traceback of the error.

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 7:16pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/5 "2021-12-26T19:16:17Z")

</div>

Traceback (most recent call last):  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py”, line 34, in inner  
response = get\_response(request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 115, in \_get\_response  
response = self.process\_exception\_by\_middleware(e, request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 113, in \_get\_response  
response = wrapped\_callback(request, \*callback\_args, \*\*callback\_kwargs)  
File “C:\Users\user\Desktop\cv\e learning\learn\quiz\views.py”, line 19, in NewQuiz  
quiz = NewQuizForm.save(commit=False)  
TypeError: save() missing 1 required positional argument: ‘self’  
[26/Dec/2021 22:15:41] “POST /quiz/1/modules/1/quiz/newquiz HTTP/1.1” 500 80644

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 7:18pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/6 "2021-12-26T19:18:20Z")

</div>

> [@HAB-DOTCOM](#):
>
> ```auto
> form = NewQuizForm(request.POST)
> if form.is_valid():
> a = Quizzes()
> quiz = NewQuizForm.save(commit=False)
> 
> ```

Your instance of the form you are working with is named `form` (the first line of this excerpt).

_That_ is what you want to save at the last line of this portion:  
`quiz = form.save(commit=False)`

See [Creating forms from models | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/forms/modelforms/#the-save-method) for more details.

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 7:22pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/7 "2021-12-26T19:22:33Z")

</div>

Tank you so much sir

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:04pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/8 "2021-12-26T20:04:14Z")

</div>

may can i ask something else?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:16pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/9 "2021-12-26T20:16:40Z")

</div>

Absolutely! This is a “conversational” location, not an “ask one question, get one answer” type of site.

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:20pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/10 "2021-12-26T20:20:49Z")

</div>

after i saved the quiz it redirect like this

```auto
return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz_id) 

```

but i got the error  
Traceback (most recent call last):  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py”, line 34, in inner  
response = get\_response(request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 115, in \_get\_response  
response = self.process\_exception\_by\_middleware(e, request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 113, in \_get\_response  
response = wrapped\_callback(request, \*callback\_args, \*\*callback\_kwargs)  
File “C:\Users\user\Desktop\cv\e learning\learn\quiz\views.py”, line 25, in NewQuiz  
return redirect(‘new-question’, course\_id=course\_id, module\_id=module\_id, quiz\_id=quiz\_id)  
NameError: name ‘quiz\_id’ is not defined  
[26/Dec/2021 23:19:56] “POST /quiz/1/modules/1/quiz/newquiz HTTP/1.1” 500 80658  
what can i do to fix this?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:22pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/11 "2021-12-26T20:22:29Z")

</div>

What is that error message telling you?

Or, to be more specific, what part of that line is it complaining about?

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:26pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/12 "2021-12-26T20:26:56Z")

</div>

the message is

# NameError at /quiz/1/modules/1/quiz/newquiz

name ‘quiz\_id’ is not defined  
the line is what i wrote in the last replay and the code is here

```auto
ef NewQuiz(request, course_id,module_id):
	user = request.user
	module = get_object_or_404(Module, id=module_id)
	if request.method == 'POST':
		form = NewQuizForm(request.POST)
		if form.is_valid():
			a = Quizzes()
			quiz = form.save(commit=False)
			quiz.module=module
			quiz.save() 
			#quiz.id=quiz_id
			module.save()

			return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz_id)  

			#course=models.Course.objects.get(id=request.POST.get('course_id'))
           
	else:
		form = NewQuizForm()

	context = {
		'form': form,
	}
	return render(request, 'quiz/newquiz.html', context)

def NewQuestion(request, course_id,module_id, quiz_id):
	user = request.user
	quiz = get_object_or_404(Quizzes, id=quiz_id)
	if request.method == 'POST':
		form = NewQuestionForm(request.POST)
		if form.is_valid():
			question_text = form.cleaned_data.get('question_text')
			points = form.cleaned_data.get('points')
			answer_text = request.POST.getlist('answer_text')
			is_correct = request.POST.getlist('is_correct')

			question = Question.objects.create(question_text=question_text, points=points)

			for a, c in zip(answer_text, is_correct):
				answer = Answer.objects.create(answer_text=a, is_correct=c, user=user)
				question.answers.add(answer)
				question.save()
				quiz.questions.add(question)
				quiz.save()
			return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz.id)
	else:
		form = NewQuestionForm()

	context = {
		'form': form,
	}
	return render(request, 'quiz/newquestion.html', context)

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:29pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/13 "2021-12-26T20:29:05Z")

</div>

Ok, this was a more targeted question.

You posted this line:

> `return redirect('new-question', course_id=course_id, module_id=module_id, quiz_id=quiz_id)`

which is the line throwing the error.

What part of _this_ line do you think the error is referring to?

And, the second question is:

> [@HAB-DOTCOM](#):
>
> NameError: name ‘quiz\_id’ is not defined

What do you think the cause of this error would be?

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:36pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/14 "2021-12-26T20:36:51Z")

</div>

i think quiz\_id is not defined in NewQuiz function but i was think that when i save the quiz in quiz.save() method the quiz\_id was also crated for that quiz…but my thought is not worked so when i think onther way of getting the quiz\_id of the crating quiz ```  
quiz.id=quiz\_id

```auto

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:39pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/15 "2021-12-26T20:39:31Z")

</div>

Correct. You have no variable defined named quiz\_id. What you are trying to reference _here_ is the `id` attribute of the `quiz` object, which is `quiz.id`, not `quiz_id`. Yes, there are a small number of places where you can use either one almost interchangably (within the ORM), but this is not one of them.

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:44pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/16 "2021-12-26T20:44:02Z")

</div>

so what do you think to fix the problem

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:47pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/17 "2021-12-26T20:47:35Z")

</div>

i mean when i tray like this

```auto
quiz_id = quiz.id

```

another probleme is come

# NoReverseMatch at /quiz/1/modules/1/quiz/newquiz

Reverse for ‘new-question’ not found. ‘new-question’ is not a valid view function or pattern name.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:49pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/18 "2021-12-26T20:49:03Z")

</div>

Ok, so we’ve solved the quiz.id issue, now it’s a different problem.

Again, what do you think the cause of this error would be?

---

<div class="post-metadata">

**Author:** ![HAB-DOTCOM](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hab-dotcom/32/6793_2.png) [@HAB-DOTCOM](https://forum.djangoproject.com/u/HAB-DOTCOM)\
**Post date:** [December 26, 2021, 8:51pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/19 "2021-12-26T20:51:49Z")

</div>

i think still the problem is that because in the Traceback i saw the previous line of code which where the error was coming  
Traceback (most recent call last):  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py”, line 34, in inner  
response = get\_response(request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 115, in \_get\_response  
response = self.process\_exception\_by\_middleware(e, request)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py”, line 113, in \_get\_response  
response = wrapped\_callback(request, \*callback\_args, \*\*callback\_kwargs)  
File “C:\Users\user\Desktop\cv\e learning\learn\quiz\views.py”, line 25, in NewQuiz  
return redirect(‘new-question’, course\_id=course\_id, module\_id=module\_id, quiz\_id=quiz.id)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py”, line 41, in redirect  
return redirect\_class(resolve\_url(to, \*args, \*\*kwargs))  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\shortcuts.py”, line 131, in resolve\_url  
return reverse(to, args=args, kwargs=kwargs)  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\base.py”, line 87, in reverse  
return iri\_to\_uri(resolver.\_reverse\_with\_prefix(view, prefix, \*args, \*\*kwargs))  
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\django\urls\resolvers.py”, line 677, in \_reverse\_with\_prefix  
raise NoReverseMatch(msg)  
django.urls.exceptions.NoReverseMatch: Reverse for ‘new-question’ not found. ‘new-question’ is not a valid view function or pattern name.  
[26/Dec/2021 23:45:03] “POST /quiz/1/modules/1/quiz/newquiz HTTP/1.1” 500 99897

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [December 26, 2021, 8:52pm UTC](https://forum.djangoproject.com/t/noreversematch-error/11232/20 "2021-12-26T20:52:37Z")

</div>

> [@HAB-DOTCOM](#):
>
> django.urls.exceptions.NoReverseMatch: Reverse for ‘new-question’ not found. ‘new-question’ is not a valid view function or pattern name.

Yes, you are correct, this is the right error.

What do you think might cause this error?

[Next page](https://forum.djangoproject.com/t/noreversematch-error/11232.md?page=2)
