Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

how to send a flask base_url to js file through html

$
0
0

I have to send a base_url of an flask function to js file since the url would be dynamic.

I was able to create the base_url for a particular flask function like

url_of_this_function = request.base_url

root_url = url_of_this_function[:url_of_this_function.rfind('/')]

pointing_url = str(url_for('filter_student'))

filter_pointing_url = ''.join([root_url,pointing_url])

I pass it to the html page through render_template

return render_template('mypage.html',\
        student_filter_link=filter_pointing_url,student_state_list=state_list)

mypage.html

<select id='student_state_selected' style='display:inline-block' onchange='get_student_filters({{ student_filter_link }})'>
     <option disabled selected>Select</option>
     {% for item in student_state_list %}
     <option value="{{item}}">{{item}}</option>
     {% endfor %}
</select>

when I try to read this in my js script it doesn't work.

function get_student_filters(filter_link) {
// Do my stuff
}

Is this the correct method to pass the url to the js? Is there a better way or am i doing something wrong here?


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>