I am struggling to get a form preview working; all I get is the same form being redisplayed over and over.
The example in the docs is helpful but frustratingly incomplete. It does not seem that there is actually a link specified between the normal form and the form preview - but I include below the relevant snippets of my code; any guidance as to what is wrong or incomplete would be appreciated!
(Footnote - I'd also like an example as to how to pass in a dictionary of values to the preview form template, in much the same way as the Django render method allows one to do. Maybe some of the existing methods listed in the docs - https://django-formtools.readthedocs.io/en/latest/preview.html - do this, but its not clear how or when; so a fuller example showing how all these would be used in an actual app might be the answer.)
# views.py
@login_required
def request_new(request):
"""Submission for new Request."""
if request.method == 'POST':
# form instance with the submitted data
form = RequestForm(request.POST)
else:
form = RequestForm()
return render(
request,
'home/request_form.html',
{'label': 'New Request',
'form': form}
)
# urls.py
from .forms import RequestForm, RequestFormPreview
urlpatterns = [
...
url(r'^request/new$', views.request_new, name='request_new'),
url(r'^post/$', RequestFormPreview(RequestForm))
# forms.py
class RequestFormPreview(FormPreview):
"""RequestForm Preview."""
preview_template = 'home/request_outcome.html' # pass in other vars?
#def get_initial(self, request):
# NOT SURE WHAT THIS IS FOR?
def done(self, request, cleaned_data):
"""Inherited method of FormPreview class."""
# process the cleaned_data
name = cleaned_data['name']
# etc. etc.
# redirect to successful outcome
return HttpResponseRedirect('/home/requests')
I am struggling to get a form preview working; all I get is the same form being redisplayed over and over.
The example in the docs is helpful but frustratingly incomplete. It does not seem that there is actually a link specified between the normal form and the form preview - but I include below the relevant snippets of my code; any guidance as to what is wrong or incomplete would be appreciated!
(Footnote - I'd also like an example as to how to pass in a dictionary of values to the preview form template, in much the same way as the Django
render
method allows one to do. Maybe some of the existing methods listed in the docs - https://django-formtools.readthedocs.io/en/latest/preview.html - do this, but its not clear how or when; so a fuller example showing how all these would be used in an actual app might be the answer.)