Our goal is to write a variable called "inputed_email" into a text file named "test3.txt". Because this takes place on the server, we need to make sure that this Python script can access the directory and text file.
@app.route('/', methods=['GET', 'POST'])
def my_form():
inputed_email = request.form.get("email")
if request.method == 'POST' and inputed_email:
# write to file
with open('/var/www/FlaskApp/FlaskApp/test3.txt', 'w') as f:
f.write(str(inputed_email))
return render_template('my-form.html', email=inputed_email)
return render_template('my-form.html')
However, the code that writes to the "test3.txt" does not work. It returns error 500 (internal server error) when ran. Any help is appreciated!