I'm learning student
On python cell. it can insert data to database(Users).
I want to insert data using post method. I can connect database. but if I use post method, it can't insert on database. there is a null value on database
I want to insert data using post method not null value. how can I fix the code?? help me :(
# -*- coding: utf-8 -*-
from flask import Flask
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_restful import reqparse, abort, Api, Resource
app = Flask(__name__)
api = Api(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:12345@localhost/catchat'
db = SQLAlchemy(app)
class Users(db.Model):
id = db.Column(db.Integer, primary_key=True)
password = db.Column(db.String(80), unique=True)
email = db.Column(db.String(120), unique=True)
def __init__(self, email, password):
self.password = password
self.email = email
def __repr__(self):
return '<Users %r>' % self.username
def user_not_exist(user_id):
if user_id not in USERS:
abort(404, message="User {} doesn't exist".format(user_id))
class UserList(Resource):
def get(self):
return USERS
def post(self):
args = parser.parse_args()
new_user = {}
new_user = Users(args['email'], args['password'])
new_user_id = db.session.add(new_user)
db.session.add(new_user)
db.session.commit()
return new_user_id, 200
api.add_resource(UserList, '/Users')
if __name__ == '__main__':
app.run(debug=True)