chore: Add askama to axum for HTML templating
This commit is contained in:
parent
677740c28c
commit
4bf97f0b95
@ -4,5 +4,7 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
askama = "0.12.1"
|
||||||
|
askama_axum = "0.4.0"
|
||||||
axum = "0.7.5"
|
axum = "0.7.5"
|
||||||
tokio = { version = "1.38.0", features = ["full"] }
|
tokio = { version = "1.38.0", features = ["full"] }
|
||||||
|
13
src/main.rs
13
src/main.rs
@ -2,12 +2,23 @@ use axum::{
|
|||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
use askama_axum::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "hello.html")]
|
||||||
|
struct HelloTemplate<'a> {
|
||||||
|
name: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(|| async { "Hello, World!" }));
|
.route("/", get(hello_world));
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn hello_world() -> HelloTemplate<'static> {
|
||||||
|
HelloTemplate { name: "world" }
|
||||||
|
}
|
||||||
|
1
templates/hello.html
Normal file
1
templates/hello.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello, {{ name }}!
|
Loading…
Reference in New Issue
Block a user