Stub in Axum templating

This commit is contained in:
Matthew Gordon 2024-02-10 13:16:37 -04:00
parent 70842b1db2
commit 856482ce17
3 changed files with 23 additions and 3 deletions

View File

@ -8,3 +8,5 @@ edition = "2021"
[dependencies] [dependencies]
tokio = { version = "1", features = ["rt-multi-thread"]} tokio = { version = "1", features = ["rt-multi-thread"]}
axum = "0.7" axum = "0.7"
askama = "0.12"
askama_axum = "0.4"

View File

@ -1,3 +1,4 @@
use askama::Template;
use axum::{routing::get, Router}; use axum::{routing::get, Router};
#[tokio::main] #[tokio::main]
@ -9,6 +10,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
async fn root() -> &'static str { #[derive(Template)]
"It works!" #[template(path = "index.html")]
struct IndexTemplate<'a> {
title: &'a str,
}
async fn root<'a>() -> IndexTemplate<'a> {
IndexTemplate { title: "LocalHub" }
} }

11
templates/index.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>{{title}}</title>
</head>
<body>
It still works!
</body>
</html>