I am trying to load a CSV file into memory in one FormView and then process it in a second FormView. Previously it worked because the choose file view only sent the filename via URL Parameters to the second view and I opened the file their. I am now opening the file in the first view and sharing the file by passing the request to the second. I want to use a FileField so the path does not need to be hardcoded.
I've stripped all the code down to the minimum but continue to get the ManagementForm Error. I've included the tag in the html file.
The error, says bound=True, valid=False but I don't know why.
form <ManagementForm bound=True, valid=False, fields (TOTAL_FORMS;INITIAL_FORMS;MIN_NUM_FORMS;MAX_NUM_FORMS)>
self <django.forms.formsets.TransactionFormFormSet object at 0x00000149C665B910>
views.py
class ChooseFileView(FormView):
template_name = 'choosefile.html'
form_class = ChooseFileForm
def form_valid(self, form):
return TransactionImportView.as_view()(self.request)
class TransactionImportView(FormView):
template_name = 'transaction_import.html'
success_url = '/'
form_class = TransactionFormSet
transaction_import.html which includes the {{ form.management_form }}
{% extends "base.html" %}
{% block main_content %}
<h1>Import Transactions</h1>
<form method="post">{% csrf_token %}
{{ form.management_form }}
{% for field in form %}
{{field}}<br>
{% endfor %}
<input type="submit" value="Import">
</form>
{% endblock %}
choosefile.html
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block main_content %}
<h1>Enter Filename</h1>
<form method="post" enctype="multipart/form-data">{% csrf_token %}
{{ form | crispy }}
<input type="submit" value="Import">
</form>
{% endblock %}
question from:
https://stackoverflow.com/questions/65861679/managementform-error-when-calling-formview-from-another-formview 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…