Beginner Tutorial: Flask Server → Localhost → Internet
:root {
--bg: #0f172a;
--card: #020617;
--text: #e5e7eb;
--muted: #9ca3af;
--accent: #38bdf8;
--warn: #f87171;
--ok: #4ade80;
--code: #020617;
--border: #1e293b;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
background: linear-gradient(180deg, #020617, #0f172a);
color: var(--text);
line-height: 1.6;
}
header {
padding: 3rem 1.5rem;
text-align: center;
border-bottom: 1px solid var(--border);
}
header h1 {
margin: 0;
font-size: 2.2rem;
color: var(--accent);
}
header p {
margin-top: 0.75rem;
color: var(--muted);
max-width: 720px;
margin-left: auto;
margin-right: auto;
}
main {
max-width: 900px;
margin: 0 auto;
padding: 2rem 1.5rem 4rem;
}
section {
background: rgba(2,6,23,0.7);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.75rem;
margin-bottom: 1.75rem;
}
section h2 {
margin-top: 0;
font-size: 1.4rem;
color: var(--accent);
}
section h3 {
margin-bottom: 0.5rem;
color: #93c5fd;
}
ul {
padding-left: 1.2rem;
}
li {
margin: 0.35rem 0;
}
code {
background: var(--code);
color: #e5e7eb;
padding: 0.15rem 0.4rem;
border-radius: 6px;
font-size: 0.95em;
}
pre {
background: var(--code);
border: 1px solid var(--border);
border-radius: 10px;
padding: 1rem;
overflow-x: auto;
margin: 1rem 0;
}
pre code {
padding: 0;
background: none;
color: #e5e7eb;
font-size: 0.95rem;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 1rem;
}
th, td {
border: 1px solid var(--border);
padding: 0.6rem 0.75rem;
text-align: left;
}
th {
background: #020617;
color: #93c5fd;
}
.ok {
color: var(--ok);
font-weight: 600;
}
.warn {
color: var(--warn);
font-weight: 600;
}
.diagram {
background: #020617;
border: 1px dashed var(--border);
border-radius: 10px;
padding: 1rem;
font-family: monospace;
white-space: pre;
overflow-x: auto;
color: #e5e7eb;
}
footer {
text-align: center;
padding: 2rem 1rem;
color: var(--muted);
border-top: 1px solid var(--border);
}
Beginner Tutorial: Flask Server → Localhost → Internet
A clear mental model of how Flask works locally, on your network, and safely on the public internet.
1. What Is localhost (Very Important)
localhost = your own computer
- When you run a Flask server and see
127.0.0.1, only your machine can access it
python app.py
Running on http://127.0.0.1:6002
Why?
127.0.0.1 is a loopback address
- Traffic never leaves your machine
2. What Is a Port
| Port |
Typical Use |
| 80 | HTTP |
| 443 | HTTPS |
| 22 | SSH |
| 6000–9000 | Development servers |
If Flask runs on port 6002, traffic must knock on that door.
3. First Flask App (Safe for Beginners)
pip install flask
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "<h1>Hello from Flask</h1>"
if __name__ == "__main__":
app.run(host="127.0.0.1", port=6002)
- ✔ Works locally
- ✖ Not accessible from the internet
4. Making It Visible on Your Network (LAN)
app.run(host="0.0.0.0", port=6002)
0.0.0.0 = listen on all network interfaces
- Other devices on your Wi-Fi can access it
ifconfig