列出html文件夹中的文件

时间:2019-03-07 08:51:55

标签: django

我正在尝试在html页面中列出pdf文件的文件夹,以便用户可以下载它们。我可以对单个文件执行此操作,但是不确定如何对文件夹执行操作。 :(

我的观点是:

def plot_graph_single_fsn(request):

    payload = {"fsns": "values",
               "signals": "signals",
               "responseFormat": "csv"
               }
    response_data = requests.post(post_api, data=json.dumps(payload))
    # Writing response to csv file
    temp_file_name = 'temp_csv.csv'
    with open(temp_file_name, 'w') as temp_file:
        temp_file.writelines(response_data.content.decode('utf-8'))

    # calling script that generated pdf folder from csv 
    csv_file = os.path.abspath('tmp.csv')
    util_path = os.getcwd()
    process = subprocess.Popen(['python', util_path + '/Utils/' + 'tmp.py', csv_file],
                               stdout=subprocess.PIPE)
    a, err = process.communicate()
    print "\n"
    return HttpResponse(folder_path)

我的包含文件的文件夹: enter image description here

模板代码:

<body>
<header>
           <a href= '{% url 'index' %}'style="background: #fffff0; color: #0f0f0f" > <span class="glyphicon glyphicon-home" aria-hidden="true">Home</span></a>
    <h2>Graph for FSN </h2>
</header>

<div class="grid-container">
    <div class="item1">
          FSN: <input type="text" class="form-control" id="FSN" required>
        <button type="submit" onclick="loadGraph()">Download</button>
    </div>
</div>

<div id="pdfdiv"></div>

<script>
    function loadGraph() {
    var fsn = document.getElementById('FSN').value;


    $.ajax({
        type: 'GET',
        url: "{% url 'plotgraphsinglefsn' %}",
        data: {
            "fsn": fsn
        },
        success: function (result) {
           console.log(result);
           for ( var key in result)
            {
            console.log("in here");
             console.log(result[key]);
             $("#pdfdiv").attr("href", result[key]);
             }

        },
        error: function (result) {

            console.log(result);
        }
    });
    return false;
    }
</script>
</body>

我正在尝试将列表中的文件名发回html,在其中我可以循环浏览它们并将它们显示为href链接。这似乎也不起作用,因为它给了我错误。

0 个答案:

没有答案