From fcc13328ff82326d25e39504732701b27f894e22 Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sat, 12 Jun 2021 20:54:43 -0600 Subject: add aspirational example derived from the django tutorial --- examples/tutorial01/main.rs | 13 +++++++++++++ examples/tutorial01/polls/mod.rs | 2 ++ examples/tutorial01/polls/urls.rs | 7 +++++++ examples/tutorial01/polls/views.rs | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 examples/tutorial01/main.rs create mode 100644 examples/tutorial01/polls/mod.rs create mode 100644 examples/tutorial01/polls/urls.rs create mode 100644 examples/tutorial01/polls/views.rs (limited to 'examples') diff --git a/examples/tutorial01/main.rs b/examples/tutorial01/main.rs new file mode 100644 index 0000000..f460e96 --- /dev/null +++ b/examples/tutorial01/main.rs @@ -0,0 +1,13 @@ +use tosin::contrib::admin; +use tosin::urls::Path; + +mod polls; + +pub const url_patterns: &[Path] = [ + Path::Include { url: "polls/", content: polls::urls::url_patterns }, + Path::Include { url: "admin/", content: admin::site::urls::url_patterns }, +]; + +fn main() { + tosin::run_server(url_patterns); +} diff --git a/examples/tutorial01/polls/mod.rs b/examples/tutorial01/polls/mod.rs new file mode 100644 index 0000000..fd1dad8 --- /dev/null +++ b/examples/tutorial01/polls/mod.rs @@ -0,0 +1,2 @@ +pub mod urls; +pub mod views; diff --git a/examples/tutorial01/polls/urls.rs b/examples/tutorial01/polls/urls.rs new file mode 100644 index 0000000..e978920 --- /dev/null +++ b/examples/tutorial01/polls/urls.rs @@ -0,0 +1,7 @@ +use tosin::urls::Path; + +use super::views; + +pub const url_patterns: &[Path] = [ + Path::View { url: "", view: views::index, name: "index" }, +]; diff --git a/examples/tutorial01/polls/views.rs b/examples/tutorial01/polls/views.rs new file mode 100644 index 0000000..8678e97 --- /dev/null +++ b/examples/tutorial01/polls/views.rs @@ -0,0 +1,5 @@ +use tosin::http::{Request, Response}; + +pub async fn index(request: Request) -> Response { + Response("Hello, world. You're at the polls index.") +} -- cgit v1.2.3