1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Update example to most recent askama release (#93)

This commit is contained in:
Hans Ole Hatzel 2019-03-17 05:35:10 +01:00 committed by Douman
parent 9d3e64d053
commit d003fa9fb4
2 changed files with 7 additions and 8 deletions

View File

@ -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"

View File

@ -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<HashMap<String, String>>) -> Result<HttpResponse> {
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() {