I have a Flask application that requires the user's date of birth for registration. A request looks something like this.
{
"username":"tayy",
"email":"tayy@dvm.com",
"password":"897ghTR$%dsa",
"first_name":"Tay",
"last_name":"Young",
"dob":"1995-01-01"
}
I am trying to deserialize the date of birth (dob). I have spent about 4 hours searching the internet for something, but so far I have come up short. The biggest issue I am running into is my data sits in a dictionary and most of the solutions only work with variables. Here is the relevent portion of the code:
@user_api.route('/', methods=['POST'])
def create():
"""
Create User Function
"""
req_data = request.get_json()
print("- - - - - - - - - - - - - - - - - - - - -")
print ("This is the data from the request:")
print (request.get_json())
print("- - - - - - - - - - - - - - - - - - - - -")
data, error = user_schema.load(req_data)
if error:
return custom_response(error, 400)
# check if user already exist in the db
user_in_db = UserModel.get_user_by_email(data.get('email'))
if user_in_db:
message = {'error': 'User already exist, please supply another email address'}
return custom_response(message, 400)
user = UserModel(data)
user.save()
ser_data = user_schema.dump(user).data
token = Auth.generate_token(ser_data.get('id'))
return custom_response({'jwt_token': token}, 201)
How can I deserealize this date so I can insert it into my Postgres database?
Comments
Post a Comment