Crates.io | askama_web |
lib.rs | askama_web |
version | |
source | src |
created_at | 2025-02-21 21:33:47.916915+00 |
updated_at | 2025-03-27 19:52:51.451283+00 |
description | A compatibility add-on for Askama to support many different web frameworks |
homepage | https://askama.readthedocs.io/ |
repository | https://github.com/rinja-rs/askama_web/ |
max_upload_size | |
id | 1564751 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A compatibility add-on for askama to support many different web frameworks.
E.g. if you are using axum, then add askama_web
with
the feature "axum-0.8"
to your Cargo.toml
:
[dependencies]
askama_web = { version = "0.12.0", features = ["axum-0.8"] }
Then just add #[derive(WebTemplate)]
to your Askama templated struct
or enum
:
use askama::Template;
use askama_web::WebTemplate;
use axum::Router;
use axum::routing::get;
#[derive(Template, WebTemplate)]
#[template(path = "hello.html")]
struct HelloTemplate {
name: String,
}
async fn hello() -> HelloTemplate {
HelloTemplate {
name: "world".to_string(),
}
}
let app = Router::new().route("/", get(hello));
By selecting the feature "axum-0.8"
, HelloTemplate
will implement axum::response::IntoResponse
.
The user will receive a "Status: 200", "Content-Type: text/html; charset=utf-8"
response with the rendered struct as body.
These web frameworks are currently implemented and can be selected with their respective feature flag:
"actix-web-4"
: implements Responder
for actix-web in version 4"axum-0.8"
/ "axum-core-0.5"
: implements IntoResponse
for axum in version 0.8 /
axum-core in version 0.5"poem-3"
: implements IntoResponse
for
poem in version 3.x"rocket-0.5"
: implements Responder
for
rocket in version 0.5"salvo-0.77"
/ "salvo_core-0.77"
: implements Scribe
for salvo in version 0.77 /
salvo_core in version 0.77"trillium-0.2"
: implements Handler
for
trillium in version 0.2"viz-0.10"
/ "viz-core-0.10"
: implements IntoResponse
for viz in version 0.10 /
viz-core in version 0.10"warp-0.3"
: implements Reply
for
warp in version 0.3As well as these logging / debugging facilities to print error messages if a template could not be rendered:
"eprintln"
: using rust's built-in eprintln!()
macro"log-0.4"
: using log as logging framework"tracing-0.1"
: using tracing as logging frameworkSome older versions are implemented, too:
"axum-0.7"
/ "axum-core-0.4"
: implements IntoResponse
for axum in version 0.7 /
axum-core in version 0.4"salvo-0.76"
/ "salvo_core-0.76"
: implements Scribe
for salvo in version 0.76 /
salvo_core in version 0.76Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.