If you write Python, Flask is the shortest path to a web app: a handful of lines gives you a page and an API. This guide deploys a working Flask app on Falix, walks the code, and shows you how to add a route that reads user input.
| At a glance | |
|---|---|
| You need | A server running the Python application |
| Plan | Any plan |
| Time | Fifteen minutes |
For how Python starts here — the app.py entry file and requirements.txt auto-install — see Python on Falix.
Step 1 — Deploy the template
Use the Flask web app template on this page. It writes two files: app.py (your code) and requirements.txt (which lists flask). On start, the Python application installs everything in requirements.txt automatically, then runs python app.py — so Flask is ready without you touching a terminal.
Press Start. The console shows the install, then Listening on port …. Open your server's address (from the Network page) in a browser for the home page, and visit /api/hello for the JSON route.
Step 2 — Read the starter code
This is the app.py the template installs:
import os
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/")
def home():
return """
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>My Flask app</title></head>
<body style="font-family: system-ui, sans-serif; text-align: center; margin-top: 4rem;">
<h1>It works!</h1>
<p>Your Flask app is running on Falix.</p>
<p><a href="/api/hello">Try the JSON API route</a></p>
</body>
</html>
"""
@app.route("/api/hello")
def hello():
return jsonify(message="Hello from your Falix API!")
if __name__ == "__main__":
port = int(os.environ.get("SERVER_PORT", 8080))
print(f"Listening on port {port}", flush=True)
app.run(host="0.0.0.0", port=port)
Each @app.route(...) maps a URL to a function. home() returns HTML; hello() returns JSON via jsonify. The bottom block is the Falix-specific part: it reads the port from SERVER_PORT and binds 0.0.0.0 — the two rules from Your first web app. Flask's built-in server is perfectly fine to start on; the app runs exactly as written with python app.py.
Step 3 — Add a route that reads input
Routes get more interesting when they respond to the request. Add request to the Flask import at the top:
from flask import Flask, jsonify, request
Then add this route anywhere above the if __name__ block:
@app.route("/api/greet")
def greet():
name = request.args.get("name", "world")
return jsonify(greeting=f"Hello, {name}!")
Save and restart. Now /api/greet returns {"greeting": "Hello, world!"}, and /api/greet?name=Sam returns {"greeting": "Hello, Sam!"}. request.args reads query-string values — that's the same ?name=... idea for every form and link on your site.
Handling a form (POST)
request.args reads values from the URL. A submitted <form method="post"> sends its fields in the request body instead, where request.form reads them. Allow the POST method on the route and pull fields out by name — this reuses the same request import from above:
@app.route("/api/echo", methods=["POST"])
def echo():
text = request.form.get("text", "")
return jsonify(you_sent=text)
request.form.get("text", "") reads the form field named text, defaulting to an empty string if it's missing. (If the client sends a JSON body rather than a form, read it with request.get_json() instead.)
A note on HTML and templates
💡 Tip: Returning an HTML string from a function, like
home()does, is completely fine while your pages are small. Once you have several pages, switch to Flask's normal setup: put.htmlfiles in atemplates/folder, CSS and images instatic/, and render pages withrender_template("page.html").
That's standard Flask with no Falix-specific twists — any Flask tutorial applies.
Step 4 — Add a package
Need another library — requests, pillow, anything on PyPI? Open the Packages page in your server menu, type the name in the Install package panel, and press Install. It updates your requirements.txt and installs the package; watch it under Tasks, then restart so your app can import it.
Troubleshooting
ModuleNotFoundError: No module named 'x'— the package isn't installed. Add it from the Packages page (it also appears as a one-click fix in the console), then restart.- Page won't load / connection refused — a port or bind issue. Confirm
app.run(host="0.0.0.0", port=port)withportread fromSERVER_PORT; then see I can't reach my app. - A route 500s — read the console traceback; it names the file and line. A tip:
print(..., flush=True)makes your own log lines appear immediately.