Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3740

Basic Flask implementation is not working

$
0
0

Hello all.

I am trying to get Editor working in a Python Flask environment.
I am currently using the following technologies:
Postgres as well as PHP for the database connections.
Python and Flask

Description of problem:
whenever I submit a new record, the returned values will not return what I typed. Instead, my table will just duplicate existing values. What is more, the POST call does not persist to the DB, because when I refresh the page, all the values are reset.

BEFORE SCREENSHOT:

MIDDLE SCREENSHOT:

AFTER SCREENSHOT:

The problem seems to be occurring when I perform a POST operation, because the tables perform the GET functionality fine.

application.py file:

@application.route('/emp_php', methods=["POST", "GET"])
def emp_php():
    out = sp.run(["php", "static/emp.php"], stdout=sp.PIPE)
    return out.stdout

HTML

{% extends 'tables.html' %}

{% block table_name %}
<head>
    <script type="text/javascript">

/*
 * Editor client script for DB table emp
 * Created by http://editor.datatables.net/generator
 */

(function($){

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: '/emp_php',
        table: '#emp',
        fields: [
            {
                "label": "fname:",
                "name": "fname"
            }
        ]
    } );

    var table = $('#emp').DataTable( {
        dom: 'Bfrtip',
        ajax: '/emp_php',
        columns: [
            {
                "data": "fname"
            }
        ],
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    } );
} );

}(jQuery));

    </script>
</head>
<table id='emp' class='table table-hover' style="width:100%">
    <thead>
    <tr>
        <th>fname</th>
    </tr>
    </thead>
        <tfoot>
    <tr>
        <th>fname</th>
    </tr>
    </tfoot>
</table>
{% endblock %}

emp.php

<?php

/*
 * Editor server script for DB table emp
 * Created by http://editor.datatables.net/generator
 */

// DataTables PHP library and database connection
include( "Editor-PHP/lib/DataTables.php" );

// Alias Editor classes so they are easy to use
use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'emp', 'id' )
    ->fields(
        Field::inst( 'fname' )
    )
    ->process( $_POST )
    ->json();

Viewing all articles
Browse latest Browse all 3740

Trending Articles