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

@ -7,4 +7,6 @@ edition = "2021"
[dependencies]
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};
#[tokio::main]
@ -9,6 +10,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
async fn root() -> &'static str {
"It works!"
#[derive(Template)]
#[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>