title: Loading static files in a Bottle.py application on openshift
body: <p>I am working on an application, hosted on openshift and built on their bottle.py quickstart example (<a href="https://github.com/openshift/bottle-openshift-quickstart" rel="nofollow">https://github.com/openshift/bottle-openshift-quickstart</a>) but I have had a hard time getting the use of static files correct. I have a local version that works with the server built into bottle but when I transfer what works locally into an openshift application it behaves differently.</p>
  
  <p>in my local main.tpl the following lines are used to indicate which files should be loaded...</p>
  
  <pre><code>&lt;link rel="stylesheet" href="{{ get_url('static', file_name='base.css') }}"&gt;
  &lt;link rel="stylesheet" href="{{ get_url('static', file_name='skeleton.css') }}"&gt;
  &lt;link rel="stylesheet" href="{{ get_url('static', file_name='layout.css') }}"&gt;
  </code></pre>
  
  <p>in my local app.py the following code attempts to serve the correct file...</p>
  
  <pre><code>app = default_app()
  
  @route('/')
  @view('main.tpl')
  def index():
      return {'get_url': app.get_url}
  
  @route('/static/&lt;file_name&gt;', name="static")
  def send_static(file_name):
      if file_name[-3:] == 'css':
          return static_file(file_name, root=os.path.join(os.getcwd(), 'static', 'styles'))
  </code></pre>
  
  <p>The conditional is there because I was trying to figure out a way to keep the /static directory organized without having to write several similar <code>send_static</code> functions, one that had the root location for css files one that had the root location for js files or whatever.</p>
  
  <p>When the code is used in openshift it no longer works, where the local version inserts a '/static/styles/base.css' into the displayed page, the openshift version only inserts '/static/base.css'. To get the css files to load I've stumbled into the following code.</p>
  
  <p>My main.tpl remains the same...</p>
  
  <pre><code>&lt;link rel="stylesheet" href="{{ get_url('static', file_name='base.css') }}"&gt;
  &lt;link rel="stylesheet" href="{{ get_url('static', file_name='skeleton.css') }}"&gt;
  &lt;link rel="stylesheet" href="{{ get_url('static', file_name='layout.css') }}"&gt;
  </code></pre>
  
  <p>But in my openshift app.py I've had to explicitly place the sub-directory into the route</p>
  
  <pre><code>application = default_app()
  
  @route('/')
  @view('main.tpl')
  def index():
      return {'get_url': application.get_url}
  
  @route('/static/styles/&lt;file_name&gt;', name="static")
  def send_static(file_name):
      if file_name[-3:] == 'css':
          root_dir = os.path.join(os.getcwd(), 'static', 'styles')
          return static_file(file_name, root=root_dir)
  </code></pre>
  
  <p>Am I missing something about the openshift server environment that causes the difference? The app is working but I would really like to know a proper way to get css files loaded and displayed.</p>
  
  <p>Thanks.</p>