Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

django forms - ManagementForm Error when calling FormView from another FormView

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...