简体   繁体   中英

Dynamically Updating HTML src with Flask and Jinja2

I have a flask template that has a video like:

<video id="firstVideo" class="clip-thumbnail" src=""></video>

and upon an update from a user click, the request's videos content updates the video like:

$('#firstVideo').attr("src", response['videos'][0]);

but I want this to be dynamically updating on the page with something like:

$('#firstVideo').attr("src", {{ url_for('static', filename='videos/' + response['videos'][0] ) }} )

Is this the right way to handle this? Will flask know to re-render the page after the update or do I need to re-render the page?

除非您在服务器上构建动态模板,否则不能使用flask模板标签,如果要从浏览器向视频URL发出ajax请求,则只需设置请求以返回完整的视频URL,然后然后完全按照您的要求更新视频src:

$('#firstVideo').attr("src", response['videos'][0]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM