diff options
| author | jerome <jerome@xlinfo.fr> | 2026-02-24 13:18:28 +0100 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2026-02-24 13:18:28 +0100 |
| commit | 93febd4968ebbf0f5a90989bbe11abcaaafcdbd1 (patch) | |
| tree | 27969e7c656077601e31da2b589b3031bc201f32 | |
| download | helloflask-master.tar.gz helloflask-master.zip | |
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | Dockerfile | 13 | ||||
| -rw-r--r-- | app/app.py | 19 | ||||
| -rw-r--r-- | app/templates/index.html | 11 | ||||
| -rw-r--r-- | app/templates/register.html | 14 | ||||
| -rw-r--r-- | requirements.txt | 9 |
6 files changed, 73 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7efb38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Created by venv; see https://docs.python.org/3/library/venv.html +bin/ +include/ +lib/ +lib64 +pyvenv.cfg +__pycache__/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dccc366 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# Stage 1: Build Stage +FROM python:slim AS build +COPY requirements.txt . +RUN python -m venv /opt/venv && . /opt/venv/bin/activate && pip install --no-cache-dir -r requirements.txt + +# Stage 2: Run Stage +FROM python:slim AS run +COPY --from=build /opt/venv /opt/venv +WORKDIR /app +COPY app /app +ENV PATH="/opt/venv/bin/:$PATH" +EXPOSE 80 +CMD ["gunicorn", "--bind", "0.0.0.0:80", "app:app"] diff --git a/app/app.py b/app/app.py new file mode 100644 index 0000000..9aa9782 --- /dev/null +++ b/app/app.py @@ -0,0 +1,19 @@ +from flask import Flask, render_template, request, redirect, url_for +import platform + +app = Flask(__name__) #On créé une instance de la classe Flask + +@app.route('/', methods=['GET','POST']) +def index(): + try: + username = request.form['username'] + return render_template('index.html',name=username,host=platform.node()) + except: + return redirect(url_for('register')) + +@app.route('/register') +def register(): + return render_template('register.html') + +if __name__ == "__main__": + app.run(host='0.0.0.0',port=8000,debug=True) diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..b4869d6 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html lang="fr"> + <head> + <meta charset="UTF-8"> + <title>Hello {{ name }}</title> + </head> + <body> + <h1>Hello {{ name }}</h1> + <p>From {{ host }}</p> + </body> +</html> diff --git a/app/templates/register.html b/app/templates/register.html new file mode 100644 index 0000000..bd39bdf --- /dev/null +++ b/app/templates/register.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html lang="fr"> +<head> + <meta charset="UTF-8"> + <title>Register</title> +</head> +<body> + <h1>Register</h1> + <form action="{{ url_for('index') }}" method="POST"> + <input type="text" name="username" placeholder="Username" required> + <button type="submit">Valider</button> + </form> +</body> +</html> diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a8ec37c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +blinker==1.9.0 +click==8.3.1 +Flask==3.1.3 +gunicorn==25.1.0 +itsdangerous==2.2.0 +Jinja2==3.1.6 +MarkupSafe==3.0.3 +packaging==26.0 +Werkzeug==3.1.6 |
