admin管理员组文章数量:1426015
Just started making a Flask app to make a simple Wizard. For now I have just two "Steps", each with its own HTML templated file; Jinja is the templating language. The first pass at this makes it so that on "Next" and "Previous" it routes to a new page.
Simple enough but now I want to convert this into a one-page app. Using Handlebars it was as simple as having a main container div, then rendering separate templates when clicking next/previous buttons.
Is there a way to do this in Flask? A way to use JS or Flask to render or load a template HTML file to a div container?
Just started making a Flask app to make a simple Wizard. For now I have just two "Steps", each with its own HTML templated file; Jinja is the templating language. The first pass at this makes it so that on "Next" and "Previous" it routes to a new page.
Simple enough but now I want to convert this into a one-page app. Using Handlebars it was as simple as having a main container div, then rendering separate templates when clicking next/previous buttons.
Is there a way to do this in Flask? A way to use JS or Flask to render or load a template HTML file to a div container?
Share Improve this question asked Feb 13, 2015 at 3:55 ZekeDroidZekeDroid 7,2095 gold badges35 silver badges59 bronze badges1 Answer
Reset to default 6You can use AJAX to load content from the server without reloading the whole page.
As an example:
<script src="http://cdnjs.cloudflare./ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready( function() {
$('#next').click(function() {
$.ajax("{{ url_for('myroute') }}").done(function (reply) {
$('#container').html(reply);
});
});
});
</script>
<input type="button" id="next" value="Next" />
<div id="container"></div>
本文标签: javascriptDynamically render template without reloading pageStack Overflow
版权声明:本文标题:javascript - Dynamically render template without reloading page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745465483a2659515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论