title: Flask: Static files in subdirectories
body: <p>In my flask template file I include a css file (I ommited the boilerplate) like this:</p>
  
  <p><code>url_for('static', filename='css/bootstrap.css')</code></p>
  
  <p>This renders to <code>/static/css/bootstrap.css</code> which means (because of leading slash) it is interpreted as <code>domain.com/static/css/boostrap.css</code>. Unfortunately the actual <code>static</code> folder is located a subdirectory: <code>domain.com/projects/test/static/</code></p>
  
  <p><strong>Environment specifics:</strong></p>
  
  <p>My fcgi file located in the <code>~/fcgi-bin</code> folder (host specific i guess):</p>
  
  <pre><code>$ cat ~/fcgi-bin/test.fcgi
  #!/usr/bin/env python2.7
  
  import sys
  sys.path.insert(0, "/home/abcc/html/projects/test")
  
  from flup.server.fcgi import WSGIServer
  from app import app
  
  class ScriptNameStripper(object):
     def __init__(self, app):
         self.app = app
  
     def __call__(self, environ, start_response):
         environ['SCRIPT_NAME'] = ''
         return self.app(environ, start_response)
  
  app = ScriptNameStripper(app)
  
  if __name__ == '__main__':
      WSGIServer(app).run()
  </code></pre>
  
  <p>and my .htaccess located in domain.com/projects/test/</p>
  
  <pre><code>$ cat .htaccess 
  &lt;IfModule mod_fcgid.c&gt;
     AddHandler fcgid-script .fcgi
     &lt;Files ~ (\.fcgi)&gt;
         SetHandler fcgid-script
         Options +FollowSymLinks +ExecCGI
     &lt;/Files&gt;
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_rewrite.c&gt;
     Options +FollowSymlinks
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)$ /fcgi-bin/test.fcgi/$1 [QSA,L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>To sum it up I want <code>url_for('static', filename='css/bootstrap.css')</code> to return <code>static/css/bootstrap.css</code> instead of <code>/static/css/bootstrap.css</code></p>
  
  <h2>EDIT #1</h2>
  
  <p>I have noticed this happens also on normal url_for calls not for static files like url_for('about').</p>
  
  <h2>EDIT #2</h2>
  
  <p>I have written a <a href="https://github.com/JonasGroeger/flask-uberspace-quickstart" rel="noreferrer">quickstart-app</a> and <a href="http://jonasgroeger.de/projekte/blog/projekt-flask-auf-dem-hoster-uberspace-blitzschnell-mit-hubschen-urls-aufsetzen/" rel="noreferrer">a blog post</a> about this.</p>