javascript - Dynamically render template without reloading page - Stack Overflow

Just started making a Flask app to make a simple Wizard. For now I have just two "Steps", eac

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 badges
Add a ment  | 

1 Answer 1

Reset to default 6

You 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745465483a4628899.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信