Click here to Skip to main content
15,896,549 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all. I have a basic DJANGO website project setup with 2 pages. I want the visitor to the website to visit a page and click a button. When the visitor clicks the button I want a python script to run. The script could be any given script on GITHUB. So for example the script scrapy.

I then want the result of the script to be printed to a CSV file.

Is this possible and how would I do it ?

Thank you

What I have tried:

I have tried numerous tutorials but none show how to do this. Mainly they return the output to the console log.
Posted
Updated 24-Jun-22 19:36pm
Comments
Maciej Los 25-Apr-22 13:21pm    
Does it really make a difference?

1 solution

Please, read this tutorial: How to create CSV output | Django documentation | Django[^]
This is very simple example:

Python
import csv
from django.http import HttpResponse

def some_view(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(
        content_type='text/csv',
        headers={'Content-Disposition': 'attachment; filename="somefilename.csv"'},
    )

    writer = csv.writer(response)
    writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
    writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"])

    return response
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900