≡

Using Python backend

Using Python backend

praabyepraabye Posts: 4Questions: 4Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: Hi!

I'm trying to use a Python backend, but I need some more documentation.

A complete example with .html, .js and relevant parts of the .py would be really nice. I've looked through published examples on datatables.net, but do not find anything like this.

I have imported the relevant libraries in my .py, I hope:

from sqlalchemy import create_engine
from datatables_server import Editor, Field, DataTable, Column

Answers

  • kthorngrenkthorngren Posts: 22,512Questions: 26Answers: 5,172
    edited 1:23PM

    There aren't any Python docs on this site. The docs for the Python library (datatables_server) should have config samples, etc. Are you using this library?

    Essentially you would configure a route, example from the above library's docs:

    @app.route("/api/staff", methods=["GET"])
    def staff():
        with engine.connect() as db:
            table = (
                DataTable(db, "staff", "id")
                .column(Column("first_name"))
                .column(Column("last_name"))
                .column(Column("position"))
                .column(Column("salary"))
            )
            table.process(request.values)
            response = table.data().to_dict()
        return jsonify(response)
    

    Then configure the Datatable to use ajax and build the table using the JSON repsonse, like this example pointing to your route. Like this:

    new DataTable('#example', {
        ajax: '/api/staff',
        columns: [
            { data: 'first_name' },
            { data: 'last_name' },
            { data: 'position' },
            { data: 'salary' }
        ]
    });
    

    Datatables and the Editor don't have knowledge of the backend so their docs won't change due to using Python. Refer to the Python library's docs for setting up the server side code.

    I can try to anwer any Python questions you have but this forum isn't setup for Python support. Please let us know of any Datatables or Editor questions you have.

    Kevin

  • allanallan Posts: 66,158Questions: 1Answers: 11,033 Site admin

    A small correction, the documentation for the DataTables Python libraries is available here and you can download a demo Editor application for Python here. That includes all of the Editor demos (nearly all of the other examples on the site are client-side specific configuration, and thus are backend independent).

    The one catch at the moment is that the upload for the Python libraries doesn't work. That is something I'll work on.

    Allan

Sign In or Register to comment.