bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.37k stars 1.46k forks source link

bottle.template() fails silently when file with same base name is in application root #1211

Closed gnbl closed 4 years ago

gnbl commented 4 years ago

On Windows 10 with

Python: 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
Bottle: 0.12.18

no output (nor error / Exception) is generated when running t.py:

import bottle
print( bottle.template('test', title="none") )

and views/test.tpl:

<h1>{{title}}</h1>

The same file with a different name, e.g. test1, works as expected.

So this string somehow trips template() https://github.com/bottlepy/bottle/blob/master/bottle.py#L4221

gnbl commented 4 years ago

Cause: there is a non-template (.tpl), non-python (.py) file with the same name test.html in the base directory where t.py resides. Feel free to close if this is working as designed - however, I think whatever is searching/finding this file then seems to disregard it as a template, causing zero output nor error.

defnull commented 4 years ago

The Bottle default template path is ['./', './views/'] and templates are allowed to end in .html, so this is unfortunate, but by design. The template logic just finds the html file first and stops looking.

gnbl commented 4 years ago

Oh, I just noticed that the html file in question was empty, so that explains the lack of output. Sorry about this...

gnbl commented 4 years ago

In case anyone else wants to modify the defaults, they are here: