Sharing with the internet


python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
mkdir c6
cd c6
pip install -r requirements.txt

It is also straightforward with httpie package, i.e.,

pip install httpie

The environment can be activated as follows,

. ~/myapp/venv/bin/activate

The files,, are organised as follows,

├── requirements.txt
├── static
│   ├── Caprion
│   ├── css
│   │   ├── index.css
│   │   └── myblog.css
│   └── js
│       └── index.js
└── templates
    ├── base.html
    └── index.html

where and our project directory Caprion/ is to be access from http://localhost:#/static/Caprion with # to be 5000 (Flask default) or 8000 (gunicorn default).


Our call is gunicorn -c app:app, where can be seen as a python program with only assignment statements.

One might as well create a configuration file such as (required to have a .py extension)

# bind = ""
bind = "unix:/home/jhz22/web.sock"
workers = 2
loglevel = "info"
errorlog = "/public/home/jhz22/logs/gunicorn_error.log"
accesslog = "/public/home/jhz22/logs/gunicorn_access.log"

Moreover, one can use uvicorn following pip install uvicorn[standard].

uvicorn app:app --host --port 8000 --workers 2


We can also apply flask routes, which gives,

Endpoint     Methods  Rule
-----------  -------  -----------------------
home         GET      /
static       GET      /static/<path:filename>
static_file  GET      /<path:path>

Furthermore, we could use curl http://localhost:8000/, curl in a familiar REST API style and/or pipe into jq to prettify.

We can use http http://localhost:8000/ with output,

HTTP/1.1 200 OK
Connection: close
Content-Length: 1223
Content-Type: text/html; charset=utf-8
Date: Mon, 27 Nov 2023 11:16:25 GMT
Server: gunicorn

<!DOCTYPE html>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Your Second Web Server</title>
    <link rel="stylesheet" type="text/css" href="/static/css/myblog.css">
    <link rel="stylesheet" type="text/css" href="/static/css/index.css">
    <div id="header">
        <h1>MyBlog Home Page</h1>
    <div id="content">
<h2>Current time: 2023-11-27 11:16:25.877095</h2>
<p><a href="">Caprion</a></p>
<p>Page visits: 1</p>
<p>List of available banner colors:</p>
<div id="color-change">
    <button class="change-banner-color">
        Change Banner Color
    <div id="footer">
        <h4>Copyright &copy; 2020 by MyBlog</h4>
    const banner_colors = ["aqua", "purple", "olive", "salmon", "lightcoral"];
<script src="/static/js/index.js"></script>