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 mechanism, refs #648 #737

Merged
merged 6 commits into from
Apr 26, 2020
Merged

Custom pages mechanism, refs #648 #737

merged 6 commits into from
Apr 26, 2020

Conversation

simonw
Copy link
Owner

@simonw simonw commented Apr 26, 2020

Refs #648. TODO:

  • Pass a view_name to render_template()
  • Mechanism for custom status code / headers / redirect
  • Documentation

@simonw
Copy link
Owner Author

simonw commented Apr 26, 2020

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.

I think I could do that with a custom template function - if that function is called during the render then we follow those instructions instead of returning the rendered HTML.
#648 (comment)

@simonw
Copy link
Owner Author

simonw commented Apr 26, 2020

Design challenge: the function that can be called in the custom template to return a custom status code and/or headers.

Proposed design:

{{ custom_headers({"x-foo": "bar"}) }}
{{ custom_status_code(404) }}

Or should I combine them into one function?

{{ custom_headers({"x-foo": "bar"}, status=404) }}

A common use-case here would be a redirect. How should that look?

{{ custom_redirect("/foo") }} - defaults to 301
{{ custom_redirect("/foo", status=302) }}

Maybe avoid dictionary syntax entirely:

{{ custom_header("x-foo", "bar") }}

@simonw
Copy link
Owner Author

simonw commented Apr 26, 2020

I'm going with custom_header(name, value), custom_status(numeric_code), custom_redirect("URL").

@simonw
Copy link
Owner Author

simonw commented Apr 26, 2020

Just needs documentation now.

@simonw simonw merged commit 304e7b1 into master Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant