title: Python, Flask, Jinja: listing directory and files: href is set incorrectly
body: <p>I am trying to list all the files and sub-directories in particular directory("/data/file/transfer"). <br> Now I have this problem only getting this file which is in the second level sub-directory. I am using Jinja template to view the page.</p>
  
  <p>Directory structure looks like : <br></p>
  
  <pre><code>/data/
   ----file/
   --------transfer/
   -------------first/
   ----------------second/
   -------------------get_this_file.txt
  </code></pre>
  
  <p><br></p>
  
  <p>the file get_this_file.txt is in /data/file/transfer/first/second/ directory. </p>
  
  <pre><code>#! /usr/bin/env python
  
  from flask import Flask,render_template, send_file
  import os
  import sys
  
  app = Flask(__name__)
  
  @app.route("/list_data", defaults={'req_path': ''})
  @app.route('/&lt;path:req_path&gt;')
  def incident_data(req_path):
      base_dir = "/data/file/transfer/"
      abs_path = os.path.join(base_dir, req_path)
      if os.path.isfile(abs_path):
          return send_file(abs_path)
      final_files = []
      if os.path.isdir(abs_path):
          files = os.listdir(abs_path)
          for file in files:
              temp_file = req_path + "/" + file
              print temp_file
              final_files.append(temp_file)
  
      return render_template('files.html', files=final_files)
  
  if __name__ == "__main__":
  
      app.config.update(dict(
          DEBUG=True,
          SECRET_KEY=b'_isecret/'
      ))
  
      app.run(host="0.0.0.0", port=8080)
  </code></pre>
  
  <p><br></p>
  
  <p>my templates/files.html is below:</p>
  
  <pre><code>&lt;ul&gt;
      {% for file in files %}
      &lt;li&gt;&lt;a href="{{ file }}"&gt;{{ file }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p><br></p>
  
  <p>OUTPUT: <br>
  on chrome: <br>
  192.168.168.xxx:8080/first/second <br>
  <br>
  first/second/get_this_file.txt  &lt;--- (when clicked) 
  192.168.168.xxx:8080/<strong>first</strong>/<strong>first</strong>/second/get_this_file.txt  <br></p>
  
  <p>Cant understand why href for get_this_file.txt is wrong. <br>
  Any help is appreciated. Struggling from a long time on this. </p>