mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
Update example to most recent askama release (#93)
This commit is contained in:
parent
9d3e64d053
commit
d003fa9fb4
@ -6,10 +6,10 @@ workspace = "../"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.5"
|
env_logger = "0.5"
|
||||||
askama = "0.6"
|
askama = { version = "0.8", features = ["with-actix-web"] }
|
||||||
|
|
||||||
actix = "0.7"
|
actix = "0.7"
|
||||||
actix-web = "0.7"
|
actix-web = "0.7"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
askama = "0.6"
|
askama = "0.8"
|
||||||
|
@ -7,6 +7,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use actix_web::{http, server, App, HttpResponse, Query, Result};
|
use actix_web::{http, server, App, HttpResponse, Query, Result};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
use askama::actix_web::TemplateIntoResponse;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "user.html")]
|
#[template(path = "user.html")]
|
||||||
@ -20,16 +21,14 @@ struct UserTemplate<'a> {
|
|||||||
struct Index;
|
struct Index;
|
||||||
|
|
||||||
fn index(query: Query<HashMap<String, String>>) -> Result<HttpResponse> {
|
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 {
|
UserTemplate {
|
||||||
name: name,
|
name: name,
|
||||||
text: "Welcome!",
|
text: "Welcome!",
|
||||||
}.render()
|
}.into_response()
|
||||||
.unwrap()
|
|
||||||
} else {
|
} else {
|
||||||
Index.render().unwrap()
|
Index.into_response()
|
||||||
};
|
}
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(s))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user