askama: askama_axum doesn't seem to work? Trait not satisfied error
Hi, One more problem I am facing trying to use askama_axum in the main branch. The Derive macro seem to have a problem adding into_response? I get this error:
error[E0277]: the trait bound
HelloTemplate: askama_axum::Templateis not satisfied –> zata-web-app-ssr\src\bin\main.rs:107:10 | 107 | #[derive(Template)] | ^^^^^^^^ the traitaskama_axum::Templateis not implemented forHelloTemplate
11 | pub fn into_response<T: Template>(t: &T, ext: &str) -> Response<BoxBody> { | ^^^^^^^^ required by this bound in
askama_axum::into_response
Epurated version of my code
use askama::Template;
use axum::{
extract,
http::StatusCode,
response::IntoResponse,
routing::{get, get_service, post},
AddExtensionLayer, Router,
};
#[tokio::main]
async fn main() {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL is not set in .env file");
let db_pool = PgPool::connect(&database_url).await.unwrap();
// Set the RUST_LOG, if it hasn't been explicitly defined
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "zata_web_app=debug")
}
tracing_subscriber::fmt::init();
let shared_state = Arc::new(AppState { db: db_pool });
// build our application with some routes
let app = Router::new()
.route("/greet/:name", get(greet))
.nest(
"/static",
get_service(ServeDir::new(concat!(
env!("CARGO_MANIFEST_DIR"),
"/static"
)))
.handle_error(|error: std::io::Error| async move {
(
StatusCode::INTERNAL_SERVER_ERROR,
format!("Unhandled internal error: {}", error),
)
}),
)
.layer(AddExtensionLayer::new(shared_state));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 8080));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn greet(extract::Path(name): extract::Path<String>) -> impl IntoResponse {
let template = HelloTemplate { name };
HtmlTemplate(template)
}
#[derive(Template)]
#[template(path = "list.html")]
struct ListTutors {
tutors: Vec<Tutor>,
}
#[derive(Template)]
#[template(path = "index.html")]
struct HelloTemplate {
name: String,
}
I also tried to do a standalone version of the example in the repo and got the same error.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (13 by maintainers)
That was it indeed, it worked! No more error.