question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bottle fails to find templates on windows

See original GitHub issue

Consider 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:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
defnullcommented, Dec 20, 2019

You were bitten by this I think: https://github.com/python/cpython/pull/10082

0reactions
defufnacommented, Dec 20, 2019

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:

3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)
D:\Development\python\bottletest/ D:\Development\python\bottletest\test
D:\Development\python\bottletest\views/ D:\Development\python\bottletest\views\test

3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)
D:\Development\python\bottletest\/ D:\Development\python\bottletest\test
D:\Development\python\bottletest\views\/ D:\Development\python\bottletest\views\test

3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)
D:\Development\python\bottletest/ D:\Development\python\bottletest\test
D:\Development\python\bottletest\views/ D:\Development\python\bottletest\views\test

2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)
('D:\\Development\\python\\bottletest/', 'D:\\Development\\python\\bottletest\\test')
('D:\\Development\\python\\bottletest\\views/', 'D:\\Development\\python\\bottletest\\views\\test')

So the original code would work with different python. Sorry for wasting your time…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found