in my case ‘new-question’ is used in the quiz urls.py file to call the NewQuestion view
path('<course_id>/quiz/<quiz_id>/newquestion', views.NewQuestion, name='new-question'),
in my case ‘new-question’ is used in the quiz urls.py file to call the NewQuestion view
path('<course_id>/quiz/<quiz_id>/newquestion', views.NewQuestion, name='new-question'),
name
attribute in that file?If you have this in an app named quiz
, you may need to reference that named url as quiz:new-question
.
See URL dispatcher | Django documentation | Django
yes it is an app and app.py file says like
class QuizConfig(AppConfig):
name = 'quiz'
and i fixed that when i added quiz:new-question
but here is another problem
Reverse for ‘new-question’ with keyword arguments ‘{‘course_id’: ‘1’, ‘module_id’: ‘1’, ‘quiz_id’: 13}’ not found. 1 pattern(s) tried: [‘quiz/(?P<course_id>[^/]+)/quiz/(?P<quiz_id>[^/]+)/newquestion$’]
i don’t know the reason
What does your function call look like at this point?
How many parameters are you passing?
How many parameters is your url expecting?
it worked sir…tank you so much for your time , but i want to talk with you in private can i?
I’m sorry, but no, I don’t do private consulations.
i don’t want private consultations…just i want you to talk some other stuff but it OK if you don’t want i will be back when i get stack.
how can i use the timer in my quiz app ?
This is a new and different topic - I suggest you open up a new subject for it, including some specifics as to what you’re trying to achieve. This includes defining what you’re trying to time and what actions you want to perform based upon timing.
For example, are you looking to track the total time it takes to complete the quiz? That’s going to get a slightly different answer than if you wanted to track the time taken for each question.
I want to track the total time it takes to complete the quiz? and after the time is completed the quiz page is hidden and see the result
i got ValueError at /quiz/None/newquestion
Field ‘id’ expected a number but got ‘None’.
from the code
def NewQuiz(request):
quizForm=forms.QuizForm()
if request.method=='POST':
quizForm=forms.QuizForm(request.POST)
if quizForm.is_valid():
quiz= quizForm.save(commit=False)
quiz_id = quiz.id
else:
print("form is invalid")
return redirect('quiz:new-question',quiz_id=quiz_id)
return render(request,'quiz/createquiz.html',{'quizForm':quizForm})
#create new question
def NewQuestion(request,quiz_id):
user = request.user
quiz = get_object_or_404(Quizzes, id=quiz_id)
questionForm=forms.QuestionForm()
if request.method=='POST':
questionForm=forms.QuestionForm(request.POST)
if questionForm.is_valid():
question=questionForm.save(commit=False)
quiz=models.quiz.objects.get(id=request.POST.get('quizID'))
question.quiz=quiz
question.save()
else:
print("form is invalid")
return redirect('quiz:new-question',quiz_id=quiz_id)
return render(request,'quiz/createqusetion.html',{'questionForm':questionForm})
what do you the this error is comes from?
Which line is giving you that error?
What is the url being invoked that takes you to the view that is throwing the error?
the error is coming from this line
quiz = get_object_or_404(Quizzes, id=quiz_id)
and the url is
path('quiz/<quiz_id>/newquestion', views.NewQuestion, name='new-question'),
Ahhh, I see the issue now.
You are on page /quiz/None/newquestion
. Your url pattern is quiz/<quiz_id>/newquestion
, so the string None
is being applied to the quiz_id
parameter.
Whatever is generating that url is what’s causing the problem. It’s sending you to an improper url.
yes that is exactly what i am getting…so what can i do to fix this problem?
You need to fix whatever it is that is sending you to that url.
What link / page / menu entry / whatever are you clicking on to send you to that location? That’s the page that needs to be fixed. It’s building a bad url and sending you to a url that’s not going to work.
this issue was fixed and i have another issue
I created a js for a countdown timer and the idea is that after the time set it will automatically submit the form .but i also want if the user check the answer and not submit before the time set it must be check the answer he checked but not submit and add the mark if he check the answer
That would entirely be JavaScript-based work. You’ll need to trigger some type of event to be fired when the timer expires. That event can check the current state of the form and submit it if appropriate.
Just be aware that you have no way to prevent the person on this page from stopping the timer and preventing it from taking any automatic action.
yeah but what about when i refresh the timer is reset ?
You already have a topic started for this. Let’s continue this discussion at how to work with the timer to the quiz fully functionality