[Fixed]-How to represent initial_dict in template when use django-formtool

1👍

I’ve solved the problem myself.
The django-formtool documentation was not enough for me.

get_form_initial(self, step): I can get the initial previous data via this function, but I can’t deliver the initial datas to the next new form for initial form data.

def get_context_data(self, form, **kwargs): This function helps me to succeed to deliver the datas from the previous form to the next form.

The right things I did are as follows:

–view.py

def get_context_data(self, form, **kwargs):
  context = super(InformationWizard, self).get_context_data(form=form, **kwargs)
  if self.steps.current == '1':
    prev_data = self.storage.get_step_data('0')
    first_name = prev_data.get('first_name','')
    last_name = prev_data.get('last_name','')
    context.update({'first_name': first_name, 'last_name': last_name})
  return context

–template.py

...
First Name: {{first_name}} Last Name: {{last_name}}
...

Leave a comment