0
我正在做一組問題,每個問題都回答是或否。取決於答案將是其他不同的問題,這個過程將會重複幾次。問題在於,每次用戶發送答案時,視圖都會重新加載並始終顯示第一個問題。 我是新的Django和網絡編程。 感謝您的回答。不要重新加載視圖Django
class ExpertoView(FormView):
template_name = "SisExperto.html"
form_class = FormExpert
success_url = 'SisExperto'
def __init__(self):
self.arbol = eval(self.fileToStr('SisExperto/enfermedades.txt')) #evalua el archivo
self.Nodoactual = self.arbol
self.pregunta = self.Nodoactual[0]
def form_valid(self, form):
#This method is calle when valid for data has been POSTED
#It should return an HttpResponse
if len(self.Nodoactual) == 3:
[self.pregunta, yesNode, noNode] = self.Nodoactual
if form.is_valid():
form_data = form.cleaned_data
respuesta = form_data.get('campo')
if respuesta == 'y':
self.Nodoactual = yesNode
else:
self.Nodoactual = noNode
self.pregunta = self.Nodoactual[0]
#el siguiente return es obligatorio
return super(ExpertoView, self).form_valid(form)
def get_context_data(self, **kargs):
""" Use this to add extra context """
context = super(ExpertoView, self).get_context_data(**kargs)
context["pregunta"] = self.pregunta
return context