Я пытаюсь создать базовое веб-приложение на python, которое позволяет запрашивать информацию через форму и электронную почту. Я пытаюсь зашифровать содержимое полей формы в теле письма, но я не уверен, что я делаю неправильно,Я получаю много разных типов ошибок, в частности, следующие, когда я пытаюсь json контент: TypeError: Объект типа ObjectId не является JSON serializable
@app.route("/", methods = ['GET', 'POST'])
def index():
form = Init(request.form)
if request.method == 'GET': # make sure the method used is define above
return render_template('home.html', form = form), logging.warning("you are under the home page now using GET, well done bacco ")
elif request.method == 'POST' and form.validate():
# the following are the data from the init form
name = form.name.data
telefono = form.telefono.data
email = form.email.data
messaggio = form.messaggio.data
# defining a new variable taking as input the values from the init form
mymsg=[{
"name": name,
"telefono": telefono,
"email" : email,
"messaggio" : messaggio
}]
# insert the list into the mongo db
x = mycol.insert_many(mymsg), print("inserting this user: ", mymsg, "in the database called ", mycol)
json_list = json.dumps(mymsg)
msg = Message('New message from: ', sender='xxxxxxx@gmail.com', recipients=['xxxxxxx@gmail.com'], body = mymsg)
msg.body = 'Messaggio: ', json_list
mail.send(msg)
return render_template('home.html', form = form), print("you are under the home page now using POST, data are sent to database")