Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom pages don't work on windows #1545

Closed
ryascott opened this issue Dec 9, 2021 · 3 comments · Fixed by #1617
Closed

Custom pages don't work on windows #1545

ryascott opened this issue Dec 9, 2021 · 3 comments · Fixed by #1617

Comments

@ryascott
Copy link

ryascott commented Dec 9, 2021

It seems that custom pages don't work when put in templates/pages

To reproduce on datasette version 0.59.4 using PowerShell on WIndows 10 with Python 3.10.0

mkdir -p templates/pages

echo "hello world" >> templates/pages/about.html

Start datasette

datasette --template-dir templates/

Navigate to http://127.0.0.1:8001/about and receive:

Error 404:
Database not found: about

@simonw
Copy link
Owner

simonw commented Dec 19, 2021

Here's the relevant code:

datasette/datasette/app.py

Lines 1204 to 1219 in 4094741

else:
# Is there a pages/* template matching this path?
route_path = request.scope.get("route_path", request.scope["path"])
template_path = os.path.join("pages", *route_path.split("/")) + ".html"
try:
template = self.ds.jinja_env.select_template([template_path])
except TemplateNotFound:
template = None
if template is None:
# Try for a pages/blah/{name}.html template match
for regex, wildcard_template in self.page_routes:
match = regex.match(route_path)
if match is not None:
context.update(match.groupdict())
template = wildcard_template
break

It's using route_path.split("/") which should be OK because that's the incoming request.path path - which I would expect to use / even on Windows. Then it uses os.path.join which should do the right thing.

I need to get myself a proper Windows development environment setup to investigate this one.

@simonw
Copy link
Owner

simonw commented Feb 3, 2022

I understand the problem now! pallets/jinja#1378 (comment)

Jinja template names/paths are not always filesystem paths. So regardless of the OS Jinja always uses forward slashes.

simonw pushed a commit that referenced this issue Feb 3, 2022
@simonw
Copy link
Owner

simonw commented Feb 3, 2022

Filed an issue with Jinja suggesting a documentation update:

simonw added a commit that referenced this issue Mar 20, 2022
simonw added a commit that referenced this issue Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants