2016-01-26 5 views
0

Bonjour les gars c'est l'application web python j'ai faitcsv fiile utilisant intranet python

""" 
    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() 

je transmets tout le résultat à region_report.html.

et region_report.html ressemble

$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> 

En region_report j'ai ajouté un bouton télécharger .Je veux faire que le travail de bouton afin que je puisse télécharger l'ensemble des données au format CSV. Quelqu'un peut-il s'il vous plaît me suggérer comment je peux le faire.

Merci

Répondre

0

Première création d'un fichier csv et de l'enregistrer sur le disque. Puis ajouter le lien <a href="your_file.csv">Download</a> au lieu de <button>.

Vous pouvez utiliser CSS pour que ce lien ressemble à un bouton.