使用python intranet下载csv fiile

时间:2016-01-26 19:04:12

标签: python csv web download intranet

大家好,这是我制作的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。任何人都可以建议我如何做到这一点。

谢谢

1 个答案:

答案 0 :(得分:0)

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

然后添加链接<a href="your_file.csv">Download</a>而不是<button>

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