flask, I want to send a json from the front end and update it to the postgresql DB wi - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: flask, I want to send a json from the front end and update it to the postgresql DB wi (/thread-9379.html) |
flask, I want to send a json from the front end and update it to the postgresql DB wi - passion044 - Apr-05-2018 //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. RE: flask, I want to send a json from the front end and update it to the postgresql DB wi - thomasp - Apr-12-2018 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/master/examples/demo_relationship.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) |