Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions MedicalReport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct MedicalReport {
patient_id: String,
name: String,
age: u8,
diagnosis: String,
treatment: String,
}

async fn get_report(patient_id: web::Path<String>) -> impl Responder {
let report = MedicalReport {
patient_id: patient_id.into_inner(),
name: "John Doe".to_string(),
age: 35,
diagnosis: "Common Cold".to_string(),
treatment: "Rest and fluids".to_string(),
};
HttpResponse::Ok().json(report)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new().service(
web::resource("/report/{patient_id}")
.route(web::get().to(get_report))
)
})
.bind("127.0.0.1:8080")?
.run()
.await
}
79 changes: 1 addition & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1 @@
# Flask Examples

Example applications for Flask beginners.

## Installation

First, you need to clone this repository:

```bash
git clone git@github.com:greyli/flask-examples.git
```

Or:

```bash
git clone https://github.com/helloflask/flask-examples.git
```

Then change into the `flask-examples` folder:

```bash
cd flask-examples
```

Now, we will need to create a virtual environment and install all the dependencies:

```bash
python3 -m venv venv # on Windows, use "python -m venv venv" instead
. venv/bin/activate # on Windows, use "venv\Scripts\activate" instead
pip install -r requirements.txt
```

## How to Run a Specific Example Application?

**Before run a specific example application, make sure you have activated the virtual enviroment.**

For example, if you want to run the Hello application, just execute these commands:

```bash
cd hello
flask run
```

Similarly, you can run HTTP application like this:

```bash
cd http
flask run
```

The applications will always running on http://localhost:5000.

## Example Applications Menu

- Hello (`/hello`): Say hello with Flask.
- HTTP (`/http`): HTTP handing in Flask.
- Templates (`/templates`): Templating with Flask and Jinja2.
- Form (`/form`): Form handing with Flask-WTF (WTForms), File upload and integrating with Flask-CKEditor, Flask-Dropzone.
- Database (`/database`): Database with Flask-SQLAlchemy (SQLAlchemy).
- Email (`/email`): Email with Flask-Mail, SendGrid
- Assets (`/assets`): Assets profiling with Flask-Assets.
- Cache (`/cache`): Cache with Flask-Caching.

## Advanced Examples Flask Applications

- [SayHello](https://github.com/greyli/sayhello): A simple message board.
- [Bluelog](https://github.com/greyli/bluelog): A blog engine that supports category and resource management.
- [Albumy](https://github.com/greyli/albumy): A full-featured photo-sharing social networking.
- [Todoism](https://github.com/greyli/todoism): A to-do application implements as SPA, it supports i18n and provides web APIs.
- [CatChat](https://github.com/greyli/catchat): A chat room based on WebSocket.

## Contributions

Any contribution is welcome, just fork and submit your PR.

## License

This project is licensed under the MIT License (see the `LICENSE` file for details).
abc
6 changes: 5 additions & 1 deletion http/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ def hello():
return response



# redirect
@app.route('/hi')
def hi():
return redirect(url_for('hello'))


@app.route('/hi2')
def hi():
return redirect(url_for('hello'))

# use int URL converter
@app.route('/goback/<int:year>')
def go_back(year):
Expand Down