Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Actualizar el contexto de FormView solo en ciertas condiciones

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

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!