Problems getting started with static files

70 views
Skip to first unread message

Dave Harper

unread,
Apr 7, 2019, 1:47:13 PM4/7/19
to bottlepy
I've been working my way through the documentation but if I'm going to be able to use Bottle, I need to be able to serve up static files.  So far, nothing I've tried has been successful so I've reduced everything down the the simplest example I can come up with.  I'm running Linux Mint and have a directory called /home/dave/test.  In that directory I have one file (staticTest.py) and one subdirectory (/home/dave/test/static).  In the static directory there is a single file ("index.html") that I'm trying to use bottle to send to the browser.  The file contents are about as simple as I can make them:

<html>
 
<h1>Hello, World</h1>
</html>


If I just click on the file, a new browser window opens and displays the message.  The staticTest.py file is also as simple as I could make it (this is right out of the documentation, the only change being the root parameter):

#!/usr/bin/env python3


from bottle import run, static_file, route


@route('/static/<filename>')
def server_static(filename):
   
return static_file(filename, root='/home/dave/test/static')


run
(host='localhost', port=8080, debug=True)

When I open a new browser window and enter "localhost:8080/index.html"  I get the 404 error.  I have tried every permutation of URL, and root parameters I can think of but everything yields the 404 error.  I tried downloading a local copy of bottle and putting print statements in it so I can try and find what's going wrong and it appears that my callback is not being registered.  For one thing, if I put a print statement prior to the return statement in my script, it doesn't print.  Further, in the Bottle def route() function, a print statement at the very end indicates that it is returning decorator rather than decorator(callback).  If I could get this simple example working, I can experiment from there to get to my final goal but without a successful Step #1, there is no Step #2.

Thanks,
Dave

Marcel Hellkamp

unread,
Apr 7, 2019, 1:53:20 PM4/7/19
to bott...@googlegroups.com

Hi Dave,

a route matches against the path-part of an HTTP request URL. In your example, '/static/<filename>' would match requests to http://localhost:8080/static/index.html and serve 'index.html' file from the '/home/dave/test/static' directory. "http://localhost:8080/index.html" does not match the route you specified, thus the 404 error.

Am 07.04.19 um 17:47 schrieb Dave Harper:
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Harper

unread,
Apr 7, 2019, 2:08:13 PM4/7/19
to bottlepy
Thanks Marcel - that did it.

Dave

Reply all
Reply to author
Forward
0 new messages