I am new to Flask (as well as whatever else is involved in what I'm trying to do, apparently) and I'm creating a small using M. Grinberg's Mega-Tutorial as reference (Flask==2.2.3, jQuery==3.6.4).
I'm trying to incorporate a range html input element
<input id="slider" type="range" min="0" max="10" name="slider" value="1"/>
whose value I'm trying to take via jQuery and use to trigger an endpoint to create an image:
@main.route("/graph.png/order=<order>")
which I then want to display in another element in the page, without re-rendering the entire thing from scratch.
I'm incorporating a script in the template:
{% block base_script %}
<script src="{{ url_for('static', filename='js/client_render.js') }}"></script>
{% endblock %}
I would think that this would do the trick:
$(document).on('input', '#polyfit_order_slider', function () {
slider_val = $('#polyfit_order_slider').get()[0]['value'];
console.log(slider_val);
$(document.getElementById('cur-input')).text('Current input: ' + slider_val)
$(document.getElementById('graph_fit')).html(
"<img src='{{ url_for('main.graph', order="+slider_val+") }}'></img>"
)
});
but it so happens that every time I move the input slider I'm getting a yellow 404 in the terminal "GET /%7B%7B%20url_for( HTTP/1.1"
and a GET http://localhost:8000/%7B%7B%20url_for( 404 (NOT FOUND)
from the console.
What is the correct syntax to use for this scenario? I've implemented the functionality using entire page re-renders on the server side by having the user click submit on a flask wtf form but I feel a more dynamic client interaction would be better, if possible.
Notes:
I'm trying to follow Flask docs' Generating URLs but when putting anything like
const user_url = {{ url_for("user", id=current_user.id)|tojson }}
in the tags I'm getting SyntaxErrors.The reference I mentioned does something very similar here.