Contents

  1. Flask
    1. Example

Flask

Example

   1 cd ~/tmp
   2 mkdir flaskproject
   3 cd flaskproject
   4 sudo apt install python3-venv
   5 python3 -m venv venv
   6 . venv/bin/activate
   7 # pip install -r requirements.txt
   8 pip install Flask
   9 find . venv/
  10 ./venv/bin/python -V
  11 ./venv/bin/python

static/app.css

   1 p{ text-align: center; }

static/app.js

   1 document.addEventListener("DOMContentLoaded", (event) => {
   2   console.log("DOM is ready!");  
   3 });

templates/index.html

   1 <html>
   2   <head> 
   3     <link href="static/app.css" rel="stylesheet">  
   4     <script src="static/app.js"></script>
   5   </head> 
   6   <body>
   7     <p>Hello Flask</p>
   8   </body>
   9 </html>

flaskproj.py

   1 from flask import Flask, render_template
   2 
   3 app = Flask(__name__)
   4 
   5 @app.route("/")
   6 def hello_world():
   7     return render_template("index.html")

   1 export FLASK_APP=flaskproj
   2 flask run  --host=0.0.0.0
   3 # http://127.0.0.1:5000/
   4 #  if the file is named app.py or wsgi.py, you don’t have to set the FLASK_APP environment
   5 

Python/Flask (last edited 2026-03-28 15:34:25 by vitor)