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

Mechanism for adding arbitrary pages like /about #648

Open
simonw opened this issue Dec 8, 2019 · 4 comments
Open

Mechanism for adding arbitrary pages like /about #648

simonw opened this issue Dec 8, 2019 · 4 comments
Labels

Comments

@simonw
Copy link
Owner

@simonw simonw commented Dec 8, 2019

For www.niche-museums.com I solved this by creating an empty about.db database file - see https://simonwillison.net/2019/Nov/25/niche-museums/

I want a neater mechanism for this.

@simonw simonw added the feature label Dec 8, 2019
@simonw

This comment has been minimized.

Copy link
Owner Author

@simonw simonw commented Dec 8, 2019

Idea: do this with a simple template naming convention.

If you hit /about and there is no matching database, check for a template file called about-page.html. If it exists, render it. Otherwise return a 404 database not found.

@simonw simonw mentioned this issue Dec 8, 2019
@simonw

This comment has been minimized.

Copy link
Owner Author

@simonw simonw commented Dec 8, 2019

Alternative idea: a new concept of "pages" which live inside templates/pages/ and where the file name minus the .html extension defines the URL.

templates/about/me.html would be served at /about/me - but only if no matching database and table were found.

This only takes effect on 404 errors from core Datasette.

@simonw

This comment has been minimized.

Copy link
Owner Author

@simonw simonw commented Dec 8, 2019

Stretch goal: it would be neat if these pages could return custom HTTP headers (eg content-type) and maybe even status codes (eg for redirects) somehow.

simonw added a commit that referenced this issue Dec 9, 2019
@simonw

This comment has been minimized.

Copy link
Owner Author

@simonw simonw commented Dec 9, 2019

The implementation in c5e8cd8 acts as a proof of concept. It has a big flaw though: it doesn't reuse the regular render() mechanism, which means it doesn't register custom template tags from plugins.

This is bad because it means that pages rendered in this way cannot take advantage of things like datasette-template-sql.

This means this issue is likely dependent on #577 - a documented mechanism to allow plugins to render templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.