Posts

Showing posts from November, 2013

Form and JSON Post Request Value to Model Mapper Functions For Flask

One of the iritating part that you have to deal with when you're handling POST requests in Flask is how you map the values into the model. It could be in JSON or in common form format. Usually this is what you do # say this is your model # using SQLAlchemy class User(db.Model): username = db.Column(db.String(50)) password = db.Column(db.String(50))         email = db.Column(db.String(50)) first_name = db.Column(db.String(50)) last_name = db.Column(db.String(50)) # this handles the common form request app.route('/process_form',methods=['POST']) def data_process(): new_user = User(                                  username = request.values.get('username')                                  password = request.values.get('password')                                  email = request.values.get('email')                                  first_name = request.values.get('first_name')                                  last_name = request.v