From d003fa9fb4a81b81871f49386095c83000050b39 Mon Sep 17 00:00:00 2001 From: Hans Ole Hatzel Date: Sun, 17 Mar 2019 05:35:10 +0100 Subject: [PATCH] Update example to most recent askama release (#93) --- template_askama/Cargo.toml | 4 ++-- template_askama/src/main.rs | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/template_askama/Cargo.toml b/template_askama/Cargo.toml index 5eba342c..03b2a3fe 100644 --- a/template_askama/Cargo.toml +++ b/template_askama/Cargo.toml @@ -6,10 +6,10 @@ workspace = "../" [dependencies] env_logger = "0.5" -askama = "0.6" +askama = { version = "0.8", features = ["with-actix-web"] } actix = "0.7" actix-web = "0.7" [build-dependencies] -askama = "0.6" +askama = "0.8" diff --git a/template_askama/src/main.rs b/template_askama/src/main.rs index 4a34abf1..50829e82 100644 --- a/template_askama/src/main.rs +++ b/template_askama/src/main.rs @@ -7,6 +7,7 @@ use std::collections::HashMap; use actix_web::{http, server, App, HttpResponse, Query, Result}; use askama::Template; +use askama::actix_web::TemplateIntoResponse; #[derive(Template)] #[template(path = "user.html")] @@ -20,16 +21,14 @@ struct UserTemplate<'a> { struct Index; fn index(query: Query>) -> Result { - let s = if let Some(name) = query.get("name") { + if let Some(name) = query.get("name") { UserTemplate { name: name, text: "Welcome!", - }.render() - .unwrap() + }.into_response() } else { - Index.render().unwrap() - }; - Ok(HttpResponse::Ok().content_type("text/html").body(s)) + Index.into_response() + } } fn main() {