I want to display a value retrieved from the database with Diesel and serve it as HTML using a Tera template with Rocket:
#[get("/")]
fn index(db: DB) -> Template {
use mlib::schema::users::dsl::*;
let query = users.first::<User>(db.conn()).expect("Error loading users");
let serialized = serde_json::to_string(&query).unwrap();
println!("query = {:?}", &serialized);
Template::render("index", &serialized)
}
It receives User { id: 1, name: "yamada" }
from the database in #[get("/")]
of src/main.rs
and tries to render it with a template. It looks good to me, but this error is returned:
Error: Error rendering Tera template 'index': Failed to value_render 'index.html.tera': context isn't an object