Bottle fails to find templates on windows
See original GitHub issueConsider this simple sample:
import bottle
@bottle.route("/")
@bottle.view("test")
def test():
return {}
bottle.run()
This sample will fail to find test.tpl on windows. It will fail for both ./ and ./view/. The reason is because os.path.abspath behavior is slightly different on windows and linux. On windows abspath preserves ending path separators, while on linux it doesn’t. So on windows abspath(“./”) returns “C:\projects\test\” while on linux it returns “/home/user/projects/test” (note the missing separator).
So when these expanded paths encounter this line in bottle.
spath = os.path.abspath(spath) + os.sep
On windows we get a path that ends with two separators. This causes this if to always fail.
if not fname.startswith(spath): continue
This leads to all path probes failing on windows, and template never gets found.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Bottlepy: template not found - Stack Overflow
I use bottle.py. When I'm going to xxx/getbio, SOMETIMES it returns : Error: 500 Internal Server Error: Template 'bio' not found.
Read more >Where are my custom templates? - Microsoft Support
After you've updated your template location, any new templates will be saved to this default location. You can search for thousands of templates...
Read more >Tutorial — Bottle 0.13-dev documentation
The default error page shows a traceback. Templates are not cached. Plugins are applied immediately. Just make sure not to use the debug...
Read more >Diy, Tutorial, Template for water bottle labels for microsoft and ...
This is a design that I came up with as a request, this video is to be used for inspiration and ideas only,...
Read more >accessing a static file in Bottle template : Forums
I have the following link find the image. have set the following on web config page. URL DIRECTORY /static/ "/user/bsneddon/files/home/bsneddon/ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

You were bitten by this I think: https://github.com/python/cpython/pull/10082
Wow it seems like my python is the problem. I’m using:
3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)I tried the same sample with other versions of Python I have, and they all behave differently from 3.7.1. Here take a look:
So the original code would work with different python. Sorry for wasting your time…