I’m making quiz app and this is an answer form with input type radio, but it’s not working(there’s no error or anything). can somebody help me fix it or suggest a different approach?
forms:
from django import forms
views:
def answers(request):
if request.method == ‘POST’:
form = AnswerForm(request.POST)
if form.is_valid():
return HttpResponseRedirect(’/thanks/’)
else:
form = AnswerForm()
What do you mean it’s “not working”? What isn’t happening that you’re expecting to have happen, or what is happening that you’re not expecting to see?
Also, when posting code here, please enclose it between lines of three backtick - ` characters to preserve the formatting of the code. This means you’ll have a line of ```, then the lines of code, then another line of ```.
sorry this is my first time posting here. So those answers should get rendered on my html page(at least that’s what I intended) but it’s just other stuff I added and there is no form.
I just didn’t include that. here it is:
def index(request):
question_list = Questions.objects.all()
context = {
‘question_list’: question_list
}
return render(request, ‘pages/questions.html’, context)
So I’ll go back to my earlier question, have you worked your way through the Django Tutorial?
(And by “working through”, I mean actually typing all the presented examples and exercises. The physical act of typing the code - and fixing the occasional mistake - greatly improves comprehension of the material. Just breezing through the material and copy/pasting it into an editor doesn’t provide nearly as much benefit.)
no I went through the tutorial and everything worked(and yes by going through I don’t mean just copy/pasting it. I want to learn for real and this is fun for me)
Cool, so then you’ll want to go back and review your work on the polls application - it’s a very close parallel to what you’re trying to do here. Pay particular attention to what data is being supplied to those views, what data is being retrieved from the database, what is being supplied to the templates, and which templates are being rendered for each page.