Python/Flask: Difference between revisions

From Omnia
Jump to navigation Jump to search
Line 56: Line 56:
References:
References:
* https://flask.palletsprojects.com/en/stable/quickstart/
* https://flask.palletsprojects.com/en/stable/quickstart/
=== Hello World Headers ===
<pre>
$ curl -i http://127.0.0.1:5000
HTTP/1.1 200 OK
Server: Werkzeug/3.1.4 Python/3.12.3
Date: Sat, 13 Dec 2025 22:05:42 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 20
Connection: close
<p>Hello, World!</p>
</pre>
== keywords ==

Revision as of 22:06, 13 December 2025

Flask

Installation

## Linux / macOS
mkdir myproject
cd myproject
# python3 -m venv .flask
python3 -m venv .venv
. .venv/bin/activate
## Windows
mkdir myproject
cd myproject
py -3 -m venv .venv
.venv\Scripts\activate
## Next Common Step
# pip install Flask
pip3 install Flask
# End
deactivate

References:

Quick Start

Hello World

helloworld.py

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>\n"


Run the server:

flask --app helloworld run

WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

Note:

* Running on http://127.0.0.1:5000

Test the server:

curl http://127.0.0.1:5000

Hello, World!

References:

Hello World Headers

$ curl -i http://127.0.0.1:5000
HTTP/1.1 200 OK
Server: Werkzeug/3.1.4 Python/3.12.3
Date: Sat, 13 Dec 2025 22:05:42 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 20
Connection: close

<p>Hello, World!</p>

keywords