Created
March 13, 2020 17:55
-
-
Save mosdevly/c8555189cc634c58b60e05e7fbe82ebc to your computer and use it in GitHub Desktop.
Revisions
-
Proto created this gist
Mar 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ {% extends 'base.html' %} {% block content %} <script src="{{ url_for('static', filename='js/example.js') }}"></script> <div id="users"> </div> {% endblock %} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ $(function() { const userDiv = $('#users'); $.get('api/users', (res) => { for (user of res) { console.log(user); userDiv.append(`<li>${user.username}</li>`); } }); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ @app.route('/example') def example(): """Example of using sqlalchemy to return JSON.""" return render_template('example.html') @app.route('/api/users') def get_all_users(): """Example of using sqlalchemy to return JSON.""" users = User.query.all() return jsonify([u.serialize() for u in users])