https://github.com/gamadorh/flask-hello-world
A simple Flask hello world application.
https://github.com/gamadorh/flask-hello-world
flask flask-app flask-application hello-world python3
Last synced: about 1 year ago
JSON representation
A simple Flask hello world application.
- Host: GitHub
- URL: https://github.com/gamadorh/flask-hello-world
- Owner: gAmadorH
- License: mit
- Created: 2021-01-20T05:10:11.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-24T19:11:01.000Z (almost 3 years ago)
- Last Synced: 2025-04-14T04:12:05.650Z (about 1 year ago)
- Topics: flask, flask-app, flask-application, hello-world, python3
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flask-hello-world
[](https://github.com/gAmadorH/flask-hello-world/blob/master/LICENSE)
A simple Flask hello world application.
## Requirements
- [Python3.8](https://www.python.org/downloads/release/python-380/)
## Create the project
Create a project folder and create a virtual environment and activate it.
```bash
mkdir flask-hello-world && cd $_
python3 -m venv .venv
source .venv/bin/activate
```
## Install Flask
First create a file to save dependencies (only Flask dependency in this case).
The must common name for this file is `requirements.txt`, so:
```bash
touch requirements.txt
```
Now you need to define your dependencies, and the file looks like this:
```txt
flask==1.1.2
```
You can check Flask releases in: [https://github.com/pallets/flask/releases](https://github.com/pallets/flask/releases).
To install it, you just to need run:
```bash
pip install -r requirements.txt
```
Now, you can check installed dependencies (Flask and its dependencies).
```bash
pip freeze
```
And the output should be like this:
```bash
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
```
WOW Flask has very few dependencies to be a web application framework,
it is because Flask is a `microframework`
## Create a Hello World app
Create a main file call `main.py` (The name does not matter, it could be another).
```bash
touch main.py
```
And then put the next code:
```python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello world with Flask'
```
## Run your new app
To run your app, first you need to set a environment variable called `FLASK_APP`
and its value is the name of your file where your app is (`main.py` in this case).
Optionally you can set the _debug mode_ for developing suing `FLASK_DEBUG` env var to 1.
```bash
export FLASK_APP=main.py
export FLASK_DEBUG=1
```
Check the env var:
```bash
echo $FLASK_APP
$ main.py
```
And then you can run your app:
```bash
flask run
```
And it outputs something like:
```bash
* Serving Flask app "main.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
```
By default Flask app run a server in the 5000 port in localhost.
Now you can send a request to your app:
```bash
curl http://127.0.0.1:5000/
```
The output should be like:
```bash
Hello world with Flask
```
To stop your new app, just press `CTRL + c`
## License
[MIT.](./LICENSE) Copyright (c)