I am getting BadValueException
error on Flask with the usage of Flask and MongoAlchemy. The issue I am having is requesting POST data from date. I tried encoding to UTF8, however is returning string, instead being instance of datetime.datetime
.
Error:
BadValueException: Bad value for field of type "date_deadline". Reason: "Value is not an instance of <type 'datetime.datetime'> (got: str)".
Python
app = Flask(__name__)
db = MongoAlchemy(app)
class Model(db.Document):
name = db.StringField()
date_added = db.DateTimeField()
@app.route('/form', methods=['GET', 'POST'])
def form():
if request.form.get('submit'):
get_name = request.form.get('name')
get_date = request.form.get('date').encode('utf8')
new_model = Model(name = get_name, date = get_date)
new_model.save()
return render_template('form.html')
HTML
<label for="name">Name</label>
<input type="text" name="name">
<label for="date">Date</label>
<input type="datetime-local" name="date">