Tengo un código en mi FormView en Django:
class SearchView(LoginRequiredMixin, FormView): template_name = "dic_records/search_form.html" form_class = KokyakuForm success_url = 'search' fetched_data = [] def form_valid(self, form): print(form.cleaned_data) kokyaku_instance = FetchKokyaku(form.cleaned_data['name_search']) err_check = kokyaku_instance.connect() kokyaku_instance.get_data() if err_check is False: messages.error(self.request, "データを出力できませんでした") return super(SearchView, self).form_valid(form) kokyaku_list = list(kokyaku_instance.get_data()) if len(kokyaku_list) == 0: messages.error(self.request, "検索のデータを見つけられませんでした") return super(SearchView, self).form_valid(form) self.fetched_data = kokyaku_list return super(SearchView, self).form_valid(form) def get_context_data(self, **kwargs): """Use this to add extra context.""" context = super(SearchView, self).get_context_data(**kwargs) context['list'] = self.fetched_data return context Y me gustaría proporcionar a la plantilla una lista de valores kokyaku_list de la variable de context , pero solo si mi form es válido y los datos se obtienen de kokyaku_instance.get_data() .
El código anterior no pasará valores