title: Displaying a .txt file in Flask
body: <p>So I'm trying to make a program using Flask that will allow users to upload a .txt file. The program will then print out this file. Using some tutorials I've found, I have the following code in a file called site.py:</p>
  
  <pre class="lang-py prettyprint-override"><code>from flask import Flask, render_template, request
  from werkzeug import secure_filename
  
  app = Flask(__name__)
  
  @app.route('/')
  def upload():
      return render_template('upload.html')
  
  @app.route('/uploader', methods = ['GET', 'POST'])
  def uploader():
      if request.method == 'POST':
          f = request.files['file']
          f.save(secure_filename(f.filename))
          content = f.read()
      return render_template("book.html", content=content)
  
  if __name__ == '__main__':
      app.run(debug = True)
  </code></pre>
  
  <p>Inside of my 'upload.html' file I have the following:</p>
  
  <pre><code>&lt;html&gt;
     &lt;body&gt;
        &lt;form action = "http://localhost:5000/uploader" method = "POST" 
           enctype = "multipart/form-data"&gt;
           &lt;input type = "file" name = "file" /&gt;
           &lt;input type = "submit"/&gt;
        &lt;/form&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and inside of my book.html file I have the following:</p>
  
  <pre><code>&lt;pre&gt;
  {{ text }}
  &lt;/pre&gt;
  </code></pre>
  
  <p>The file uploader is definitely working - the files are being saved in the correct directory in my computer, but the text in the files isn't being displayed, namely the last two lines of my site.py:</p>
  
  <pre class="lang-py prettyprint-override"><code>        content = f.read()
      return render_template("book.html", content=content)
  </code></pre>
  
  <p>don't seem to be doing anything.</p>
  
  <p>How can I fix this problem?</p>
  
  <p>Thanks!</p>