If I understood you correctly, you basically want to change the actual python file base on the user input. Probably not. Because multiple users will have separate input.
Here's the things you might want(or might help you) regardless of what I understood.
To get the input from a post request -
Simply use request.form.get('name')
to get the data.
Furthermore here.
You might want to use JavaScript to send post data.
Try this-
var element = document.getElementById('yearInputId')
var xhr = new XMLHttpRequest()
xhr.open('/url') \\the route you want this data to handle
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
xhr.send("year=" + element.value)
You may want to store the year in a database or session variable
See using db with flask & using sessions
Storing in a session variable might do the work if you don't want to store the year but just as temporally.
If you want to serve '/' based on the post request
#check if request method is post
if request.method == 'POST':
year = request.form.get('year') #change year to your html post variable name
return render_template("index.html", output=year)
else if request.method == 'GET':
return render_template("index.html", output=output)
and yes, make sure to enable post request in the route.
@app.route('/', mothods=['POST', 'GET'])
Advices -
- You probably want to make a separate route for the post data to process.
- Use database or sessions depending on your goal. When serving future requests, just the parse the year. You may need to store a unique identifier. Like username or browser cookie along with the year.
- Use JavaScript if you're updating something just locally.