S
S
semolex2014-04-17 14:02:01
backbone.js
semolex, 2014-04-17 14:02:01

How to show data from backend (Flask) to frontend view (Backbone)?

Hello! There is a set of data on the backend that needs to be shown in a table on the frontend...
Right now Flask does it, but we need to do it with Backbone.
Here is some code:
The route that gives the data:

@app.route('/admin')
def admin_usr():
    if 'username' in session:
        all_users = Users().get_all_users()
        return render_template('admin.html', title='Admin', all_users=all_users)
    return redirect(url_for('index'))

And template on the flask:
</thead>

    <tbody>
    {% for usr in all_users %}
      <tr>
        <td>{{usr.l_name}}</td>

        <td>{{usr.f_name}}</td>

        <td>{{usr.login}}</td>

        <td>{{usr.email}}</td>

        <td>{{usr.id_role}}</td>

        <td>
          <div class="small success btn">
            <a href='/edit_user?id={{usr.id}}'>Edit</a>
          </div>
        </td>

How to do the same but with Backbone?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kolofut, 2014-11-20
@semolex

The point is that your backend would only give index.html once with the entire Backbone application, and then return only JSON, that is, you are already implementing a REST-full API, where your models will communicate via this API.
That is, for example, in order to implement what you have written in flask tempalate,
On the frontend:
On the backend:

  • Actually implement a route that will return JSON in the format that your backbone model expects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question