the same code works perfectly in the same way in other project …let me show you the code and the image
i used in the content template like this
<li><a href="{% url 'new-quiz' course.id module.id %}">
Add new quiz</a></li>
in the urls
from django.urls import path
from quiz.views import NewQuiz, NewQuestion, QuizDetail, TakeQuiz, SubmitAttempt, AttemptDetail
urlpatterns = [
path('<course_id>/modules/<module_id>/quiz/newquiz', NewQuiz, name='new-quiz'),
path('<course_id>/modules/<module_id>/quiz/<new_quiz_id>/newquestion', NewQuestion, name='new-question'),
path('<course_id>/modules/<module_id>/quiz/<new_quiz_id>/', QuizDetail, name='quiz-detail'),
path('<course_id>/modules/<module_id>/quiz/<new_quiz_id>/take', TakeQuiz, name='take-quiz'),
path('<course_id>/modules/<module_id>/quiz/<new_quiz_id>/take/submit', SubmitAttempt, name='submit-quiz'),
path('<course_id>/modules/<module_id>/quiz/<new_quiz_id>/<attempt_id>/results', AttemptDetail, name='attempt-detail'),
]
in views
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseForbidden
from quiz.forms import NewQuizForm, NewQuestionForm
from quiz.models import Answer, Question, Quizzes, Attempter, Attempt
from courses.models import Module
from users.models import CustomUser
#from completion.models import Completion
# Create your views here.
def NewQuiz(request, course_id, module_id):
user = request.user
module = get_object_or_404(Module, id=module_id)
new_quiz=None
if request.method == 'POST':
quiz_form = NewQuizForm(request.POST)
if quiz_form.is_valid():
new_quiz=quiz_form.save(commit=False)
new_quiz.module = module
new_quiz.save()
return redirect('new-question', course_id=course_id, module_id=module_id, new_quiz_id=new_quiz.id)
else:
quiz_form = NewQuizForm()
context = {
'quiz_form': quiz_form,
}
return render(request, 'quiz/newquiz.html', context)
def NewQuestion(request, course_id, module_id, new_quiz_id):
user = request.user
quiz = get_object_or_404(Quizzes, id=new_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, user=user, 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, new_quiz_id=new_quiz_id)
else:
form = NewQuestionForm()
context = {
'form': form,
}
return render(request, 'quiz/newquestion.html', context)
as you see this is in the other project and when i clicked add new quiz it worked like this
in this code where is Those parameters (course_id and module.id) supply ? can you show me the difference?