【问题标题】:Downloading csv fiile using python intranet使用 python 内网下载 csv 文件
【发布时间】:2016-01-26 19:04:12
【问题描述】:

大家好,这是我制作的 Python Web 应用程序

    """
    This is where  we start the actual web application
    """
    number_of_leads= counter
    unmatched_leads= len(getLeadSettings(in_leads)[0])
    #lead_details=[number_of_leads,unmatched_leads]

    pop_before=int(getPop(coveredzips))
    for z in ziplist:
        if z not in coveredzips:
            coveredzips+=[z]

    pop_after=int(getPop(coveredzips))
    ziplist_pop_percentage=float((ziplist_pop*100.0)/pop_before)
    popdata = [ziplist_pop, pop_before, pop_after,ziplist_pop_percentage]

    number_can_generate= str(float((number_of_leads)/(ziplist_pop/1000000.0))) + " leads per Million"

    lead_details=[number_of_leads,unmatched_leads,number_can_generate]

    file=csv_file
    return render.region_report(partners = partners, popdata = popdata ,lead_details=lead_details,file=file)
    return render.index(greeting = greeting)



    #l=getRegionsWithPop(current_regions)
    #u=getRegionWithPop(l)
    #return u
if __name__ == "__main__":
    app.run()

我将整个结果转发到 region_report.html。

region_report.html 看起来像

$def with (partners, popdata , lead_details,file)

<html>

    <head>
        <title>Agents with overlapping territories</title>
    </head>
    <h2 align="center" style="color:green">Partner details with overlapping territories</h2>
$if partners:
    <table border="1" style="width:100%" bgcolor="#FFFFCC"  border="black" >
    <tr><td><b>PID</b></td><td><b>Name</b></td><td><b>Lead limit</b></td><td><b>Profit</b></td><td><b>Region percentage</b></td><td><b>Number of leads</b></td></tr>
    $for pid,data in partners.items():
        <tr><td>$pid</td><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td></tr>
    </table>
$else:
    Oops!
<br/>   
$if popdata:
    <table border="1" style="width:38.5%" bgcolor="#FFFFCC" >
    <tr><td><b>Zip list population<b></td><td>$popdata[0]</td></tr>
    <tr><td><b>Total covered population without ziplist<b></td><td> $popdata[1]</td></tr>
    <tr><td><b>Total covered population with ziplist</td><td> $popdata[2]</td></tr>
    <tr><td><b>Percentage of the population covered </td><td> $popdata[3]</td></tr>
$if lead_details:
    <tr><td><b>Number of leads in the ziplist from the last month </td><td> $lead_details[0]</td></tr>
    <tr><td><b>Number of leads which are unmatched in the last month </td><td> $lead_details[1]</td></tr>
    <tr><td><b>Number of leads we can generate on average </td><td> $lead_details[2]</td></tr>
    </table>
    <button type="submit" value="Submit">Download</button>
$else:
    Oops!

</body>
</html>

在 region_report 中,我添加了一个下载按钮。我想让该按钮工作,以便我可以将整个数据下载为 csv。谁能建议我如何做到这一点。

谢谢

【问题讨论】:

    标签: python csv web download intranet


    【解决方案1】:

    首先创建csv 文件并将其保存在磁盘上。

    然后添加链接&lt;a href="your_file.csv"&gt;Download&lt;/a&gt; 而不是&lt;button&gt;

    您可以使用CSS 使此链接看起来像按钮。

    【讨论】:

      猜你喜欢
      • 2019-01-15
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 2020-05-25
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多