I am creating a single webpage and I would like to go to a specific section (in this case called results) of that page using Flask's render_template.
Is there any way to do so, for example by passing in an argument go_to_results = True into render_template:
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
return render_template('index.html')
file = request.files['file']
if file.filename == '':
return render_template('index.html')
prediction = predict(file, 3, percentage=True)
return render_template('index.html', prediction_html = prediction, go_to_results = True)
return render_template('index.html')
I found this example but it doesn't fit my needs, as I am using only 1 HTML page ('index.html'). Link to a specific location in a Flask template.
UPDATE WORKING SOLUTION: I added this to the HTML results section:
<a href="#results">
</a>
And then I used this JS code.
<script>
function jumpToHash(hash){
if (hash){
var url = location.href;
location.href = "#results";
}
}
jumpToHash({{ anchor }});
</script>