The functionality you're describing doesn't align perfectly with the idea of a "static" web application, since you're expecting some server-side processing (running parts of a Python script based on user input). Azure Static Web Apps primarily serve static content without any server-side processing. In your case, an Azure Web App (especially one designed for Python, like the Flask-based tutorial you linked) would be more appropriate.
https://devblogs.microsoft.com/devops/comparing-azure-static-web-apps-vs-azure-webapps-vs-azure-blob-storage-static-sites/
To avoid rerunning the first half of the Python script, you can:
Use Flask's session or caching mechanisms to store the results of the first half of the script, so they don't need to be recalculated if the user returns to the search page or Split your script into functions, so you can call just the parts you need at any given time.
below is how you may structure your flask app
from flask import Flask, render_template, request, redirect, url_for, session
app = Flask(__name__)
app.secret_key = 'some_secret_key'
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
search_term = request.form.get('search_term')
# Process the first half of your script here
session['result_first_half'] = some_result
return redirect(url_for('results', search_term=search_term))
return render_template('search.html')
@app.route('/results')
def results():
search_term = request.args.get('search_term')
# Process the second half of your script here, using the results from the first half
data_from_first_half = session.get('result_first_half')
result = process_second_half(data_from_first_half, search_term)
return render_template('results.html', result=result)
if __name__ == '__main__':
app.run(debug=True)
The root route displays a search box and processes the first half of your script when a search term is submitted.
The results route processes the second half of your script and displays the results.
The results from the first half of the script are stored in the Flask session to avoid recalculating them.