fetch("../api/anomalies",{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"position": x,
"position_y": y,
"a_half_axis": 20,
"b_half_axis": 20,
"camera_id": camera,
"inspection_id": myInspection,
"label": anomaly_type,
"confirmed": true,
"modifier": email
})
}).catch((error) => {
console.error(error);
});
The backend looks as follows:
# policy definitions
policy = Policy()
policy.set('*', 'GET', authorize=True, allowed_patterns=['*'])
# for security reasons we disabled here all methods but GET at the policy level,
# to enable any of them just set authorize = True
policy.set('*', 'PUT', authorize=False)
policy.set('anomalies', 'POST', authorize=True)
policy.set('*', 'DELETE', authorize=False)
@action('api/<tablename>/', method = ['GET', 'POST'])
@action('api/<tablename>/<rec_id>', method = ['GET', 'PUT', 'DELETE'])
@action.uses(db)
def api(tablename, rec_id=None):
return RestAPI(db, policy)(request.method,
tablename,
rec_id,
request.GET,
request.POST
)
However nothing gets inserted into the database. I have just started with py4web and it would be a big time saver, if I could insert these records programmatically. By the way: fetching a record works perfect.
Any idea what I have done wrong?
Many thanks
Stefan Messmer