0

I have a Python script that loops through a list of SQL queries read from an Excel file, executes them, and stores output results to a .csv file.

Currently I trigger this from the command line locally. I would like to create a very basic Web page, something that basically has a button to click to execute the Python script for now. If I can get the output file stored there somehow as well, even better.

The idea being I would start with it locally, but then move the web page somewhere where my team could access it and do the same thing.

I don't need much functionality at all for this web page obviously but this stuff is new to me so not quite sure where to start. Any ideas?

Thanks

1
  • python3 -m http.server Commented Dec 17, 2017 at 12:07

1 Answer 1

2

I guess Flask would be a decent choice for a simple web app.

folder structure:

├── app.py
├── static
│   ├── index.html

app.py (EDIT added index.html route handling, duh doy)

from flask import Flask
app = Flask(__name__, static_url_path='', template_folder='static')

@app.route('/')
def index():
    return app.send_static('index.html')

@app.route('/execute')
def execute_sql_logic():
    # Do stuff here
    return 'SQL executed', 200

if __name__ == '__main__':
    app.run()

You'll need to export FLASK_APP=app.py in your working directory

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <a href='/execute'><button>execute SQL</button></a>
</body>
</html>

Simplest example I could think of.
Now when you'll run app.py and navigate to localhost:5000 (Port defaults to 5000 if I remember correctly) you'll see the HTML page with the execute SQL button. Clicking on it will send a GET to localhost:5000/execute which in turn will call your function.
Deploying on a server is beyond the scope of this answer unfortunately.

Sign up to request clarification or add additional context in comments.

1 Comment

Great, thanks for taking the time to explain that to me. I will look into it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.