Home > Net >  Get input from front-end of the website and generate file corresponding in python
Get input from front-end of the website and generate file corresponding in python

Time:01-17

i am creating an website in which the users are going to input some form data and from the form data that the user given i will generate a excel file based on it using python, my python script is already done, but i dont know how i can connect it to the front-end / javascript so the i can pass the data to my python file script download the excel file to the user, i was looking at some django / flask tutorials but haven't found nothing that solves my problem, thanks for any reply in advance

CodePudding user response:

creating a excel file from form data you can use pandas https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_excel.html

CodePudding user response:

First you need to have a Django or Flask project. Let's say, Django.

  1. Then you an endpoint for API.
  2. POST the data from frontend to back-end using that API end point.
  3. Once the data received on django side, run your script and download the excel file. You can send that excel file to front-end as well for download.

CodePudding user response:

It would be easier if you could show some dummy code you have tried yourself.

So as I understand, you have a script.py ready that will generate the excel file and tested it yourself in command line. But you're not sure how to implement in the Django and get desired results.

Define a function in your views.py file along the lines of:

def excel_creator(param1,param2):...     
  • Add the contents of your script.py in the function .
  • Then get the user input
  • Pass those input values as parameters in the function
  • Then work on making the output file downloadable for user (refer Django official documentations ).
  •  Tags:  
  • Related