如何将<input webkitdirectory mozdirectory>上传的文件夹名返回到视图.py在djang

2024-04-19 17:56:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Django项目中有一个HTML文件,其中包含使用

 <input type="file" name="file" id="uploadFolder" webkitdirectory mozdirectory/>

我要将选定的文件夹路径传递到视图.py。我尝试使用FormData的概念,但我得到的只是文件名,而不是文件夹路径。我做了如下的事情:

      <form method="POST" enctype="multipart/form-data" id="fileUploadForm">
                        {% csrf_token %}

                        <input type="file" name="file" id="uploadFolder" webkitdirectory mozdirectory/><br/><br/>


                        <input type="button" value="Submit" id="btnSubmit"/>


   </form>

在Button cllick上有这样的东西:

 $(document).ready(function () {



  $("#btnSubmit").click(function (event) {
                $("#result").text("Processing...");

    //stop submit the form, we will post it manually.
    event.preventDefault();

    // Get form
    var form = $('#fileUploadForm')[0];

    // Create an FormData object
    var data = new FormData(form);

    // disabled the submit button
    $("#btnSubmit").prop("disabled", true);

    $.ajax({
        type: "POST",
        enctype: 'multipart/form-data',
        url: "/upload/",
        data: data,
        processData: false,
        contentType: false,
        cache: false,
        timeout: 600000,
        success: function (data) {

            $("#result").text(data);
            console.log("SUCCESS : ", data);
            $("#btnSubmit").prop("disabled", false);

        },
        error: function (e) {


        }
    });

});

 });

如何获取完整路径(或文件夹名)?你知道吗


Tags: name路径form文件夹idfalseinputdata