Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#19886 closed Bug (duplicate)

documentation: FormWizard.as_view() does not have the attribute get_form()

Reported by: gandalf013@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The documentation for form wizards has this example:

>>> from myapp.forms import ContactForm1, ContactForm2
>>> from myapp.views import ContactWizard
>>> initial = {
...     '0': {'subject': 'Hello', 'sender': ''},
...     '1': {'message': 'Hi there!'}
... }
>>> wiz = ContactWizard.as_view([ContactForm1, ContactForm2], initial_dict=initial)
>>> form1 = wiz.get_form('0')
>>> form2 = wiz.get_form('1')
>>> form1.initial
{'sender': '', 'subject': 'Hello'}
>>> form2.initial
{'message': 'Hi there!'}

The above example (with the definitions of ContactForm1, ContactForm2, and ContactWizard from earlier) fails:

AttributeError: 'function' object has no attribute 'get_form'

It seems like the example assumes that as_view() should return an instance of ContactWizard, whereas it actually returns a function.

Change History (2)

comment:1 Changed 4 years ago by Carl Meyer

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

Thanks for the report! This is a duplicate of #19880.

comment:2 Changed 4 years ago by Tim Graham

You can't initialize ContactWizard directly with a list of forms and the initial dict. The as_view call is correct, but then you need to pass request to the function that's returned. Maybe RequestFactory could be used for the example, but a session is also needed on the request so it seems a bit complicated to have this example use the shell.

Note: See TracTickets for help on using tickets.
Back to Top