title: Error 404 when trying to set up a Bottle-powered web app on Apache/mod_wsgi
body: <p>I am a beginner programmer. I started using Python and Bottle for a small web app to print a form, so far so good. The real issue is configuring Apache and <code>mod_wsgi</code>, as my knowledge is almost none.</p>
  <p><strong>My problem</strong>: I keep getting this error:</p>
  <blockquote>
  <p>Error 404: Not Found</p>
  <p>Sorry, the requested URL /factura/ caused an error: Not found</p>
  </blockquote>
  <p>In work they gave me and address redirecting to a IP:port; after some days of reading Apache docs and looking examples through the web I managed to set up the configuration so my VirtualHost doesn't breaks the others virtualhosts already running. The config looks like this (based on the bottle tutorial deployment section):</p>
  <pre><code>Listen port
  NameVirtualHost IP:port
  
  &lt;VirtualHost IP:port&gt;
      ServerName IP:port
  
      WSGIDaemonProcess factura processes=1 threads=5
      WSGIScriptAlias / /var/www/factura/app.wsgi
  
      &lt;Directory /var/www/factura&gt;
          WSGIProcessGroup factura
          WSGIApplicationGroup %{GLOBAL}
          Order deny,allow
          Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>My <code>app.wsgi</code> is almost the same as the one in the Bottle tutorial-deployment section. I only added the line <code>sys.stdout = sys.stderr</code>:</p>
  <pre><code>import sys, os, bottle
  
  # Change working directory so relative paths (and template lookup) work again
  sys.path = ['/var/www/factura'] + sys.path
  os.chdir(os.path.dirname(__file__))
  
  # Error output redirect
  # Exception KeyError in 'threading' module
  sys.stdout =  sys.stderr
  
  import factura
  application = bottle.default_app()
  </code></pre>
  <p>Here is a bit of the python code which is related to Bottle:</p>
  <pre><code>from lib import bottle
  
  app = bottle.Bottle()
  
  #serves files in folder 'static'
  @app.route('/static/:path#.+#', name='static')
  def ...
  
  @app.route(&quot;/factura&quot;)
  @bottle.view(&quot;factura&quot;)
  def ...
  
  @app.route(&quot;/print_factura&quot;, method=&quot;POST&quot;)
  def ...
  </code></pre>
  <p>I have read some of the others question similar to this, but I can't manage to see what I'mm missing. I suppose the problem is in <code>app.wsgi</code>?</p>
  <p><strong>UPDATE</strong></p>
  <p>file structure</p>
  <pre><code>/var/www/factura/       ## .py files
                  /views  ## here is the web template
                  /static ## .css and .js of template
                  /lib    ## package with bottle and peewee source files
                  /data   ## inkscape file to play with
                  /bin    ## backup stuff in repo, not used in code
  </code></pre>
  <p>Apache error log only shows</p>
  <p><code>Exception KeyError: KeyError(-1211426160,) in &lt;module 'threading' from '/usr/lib/python2.6/threading.pyc'&gt; ignored</code>
  that is a warning from wsgi/python issues, harmless by <a href="http://code.google.com/p/modwsgi/issues/detail?id=197" rel="nofollow noreferrer">wsgi issue 197</a></p>
  <p><strong>UPDATE 2</strong> working
  <br /> added <code>@app.route(&quot;/factura/&quot;)</code> notice the trail slash, that with the change in app import <code>from factura import app as application</code> those two together made it work</p>