Python Forum
flask, I want to send a json from the front end and update it to the postgresql DB wi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flask, I want to send a json from the front end and update it to the postgresql DB wi
#1
//run.py
from flask import Flask, render_template, jsonify, request
from flask_cors import CORS
from src.models.models import Memeber0
from src.models.dbconn3 import db

app = Flask(name)
CORS(app)

@app.route('/json_test', methods=['GET', 'POST'])
def json_test():
if request.method == "POST":
index = jsonify(request.json.get('index'))
agency = jsonify(request.json.get('agency'))
name = jsonify(request.json.get('name'))
feature = jsonify(request.json.get('feature'))
depiction = jsonify(request.json.get('depiction'))
Memeber0.query.filter(Memeber0.index == index).update(dict(
agency=agency, name=name, feature=feature, depiction=depiction
))
db.session.commit()
return index

----------------------

I want to send a json from the front end and update it to the postgresql DB with that data.
But I did this, but I can not do it. What should I do?
I would like you to give us a simple example.
Reply
#2
Hi,

You can use this package: https://github.com/thomaxxl/safrs . It creates a full-blown json frontend to a db backend.

an example can be found here: https://github.com/thomaxxl/safrs/blob/m...ionship.py . The example uses sqlite but you can use postgres if you change the database connection configuration:

app.config.update(SQLALCHEMY_DATABASE_URI='sqlite://', DEBUG=True)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask TypeError: Object of type Decimal is not JSON serializable mekacharan 0 1,508 Jul-15-2021, 05:28 AM
Last Post: mekacharan
  Sending How to send private message with Flask-Socketio and Vue jonte 0 2,386 Jul-28-2020, 08:14 PM
Last Post: jonte
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 892 May-11-2020, 04:58 PM
Last Post: jenkins43
  [flask] mail.send giving error SheeppOSU 2 1,464 May-31-2019, 09:31 PM
Last Post: SheeppOSU
  Flask rest api How to retrieve json request raysefo 4 4,144 Jan-20-2019, 06:46 PM
Last Post: raysefo
  Paginate json data in flask or jinja2 soli1994 1 6,061 Jun-28-2018, 06:00 PM
Last Post: gontajones
  Trying to use flask_login from front end with rauth rahul3103 1 2,464 Jan-08-2018, 11:04 AM
Last Post: SarbjitGrewal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020