I'm trying to upload a simple text file and then display it in another URL in flask. However, I'm getting a blank output with b" as the only thing showing. Its just a regular text file with utf-8.
Here's the code -
def upload_source():
if request.method == 'POST':
# check if the post request has the file part
f = request.files['file']
if f.filename == "":
print("No file Name")
return redirect(request.url)
if not allowed_file(f.filename):
print("File extension not allowed!")
return redirect(request.url)
else:
full_filename = secure_filename(f.filename)
f.save(os.path.join(app.config['UPLOAD_FOLDER'], full_filename))
print("File saved")
content = f.read()
return render_template('source.html', text=content)
and i'm including this in the source html
<p> {{ text }} </p>
I'm relatively new to python and flask and I appreciate your help here. Thank you!