mirror of
https://github.com/actix/examples
synced 2025-06-28 18:00:37 +02:00
port more examples
This commit is contained in:
@ -2,14 +2,13 @@
|
||||
name = "template-askama"
|
||||
version = "0.1.0"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
workspace = "../"
|
||||
workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
env_logger = "0.5"
|
||||
env_logger = "0.6"
|
||||
askama = "0.6"
|
||||
|
||||
actix = "0.7"
|
||||
actix-web = "0.7"
|
||||
actix-web = { git="https://github.com/actix/actix-web.git", branch = "1.0" }
|
||||
|
||||
[build-dependencies]
|
||||
askama = "0.6"
|
||||
|
@ -1,11 +1,9 @@
|
||||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
#[macro_use]
|
||||
extern crate askama;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use actix_web::{http, server, App, HttpResponse, Query, Result};
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, Result};
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
@ -19,7 +17,7 @@ struct UserTemplate<'a> {
|
||||
#[template(path = "index.html")]
|
||||
struct Index;
|
||||
|
||||
fn index(query: Query<HashMap<String, String>>) -> Result<HttpResponse> {
|
||||
fn index(query: web::Query<HashMap<String, String>>) -> Result<HttpResponse> {
|
||||
let s = if let Some(name) = query.get("name") {
|
||||
UserTemplate {
|
||||
name: name,
|
||||
@ -33,17 +31,11 @@ fn index(query: Query<HashMap<String, String>>) -> Result<HttpResponse> {
|
||||
Ok(HttpResponse::Ok().content_type("text/html").body(s))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sys = actix::System::new("template-askama");
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
// start http server
|
||||
server::new(move || {
|
||||
App::new().resource("/", |r| r.method(http::Method::GET).with(index))
|
||||
HttpServer::new(move || {
|
||||
App::new().service(web::resource("/").route(web::get()).to(index))
|
||||
})
|
||||
.bind("127.0.0.1:8080")
|
||||
.unwrap()
|
||||
.start();
|
||||
|
||||
println!("Started http server: 127.0.0.1:8080");
|
||||
let _ = sys.run();
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user