How to publish a Python app
Create a small Flask app, publish it on your domain with WebShield, then check its logs, update it and roll back.
A Python web app needs a running process to accept requests from the internet. In Apps, WebShield builds your code, runs it and connects your domain over HTTPS.
We will start with Flask: a single page asks for a name and displays a greeting. This example does not need a database.
What you get: an app at app.example.com that you can update from your terminal
and roll back from the control panel.
You need: a WebShield account, your own domain and a Linux, macOS or WSL terminal.
For a local check, you also need Python 3.10 or later. Time: about 30 minutes,
excluding DNS propagation.
1. Create a project and an app
Section titled “1. Create a project and an app”Open Services → Apps in the control panel.
Review the prices and usage billing terms, then create a project called hello.
When creating your first project, confirm the billing terms in the dialog that opens.
Inside it, create an app called web: choose App as its kind and port 8080.
Leave the other settings at their defaults.
The project groups related apps and databases; web is the individual service that
will run our code. Its card should now appear inside hello.
2. Prepare the files
Section titled “2. Prepare the files”Create an empty directory called flask-hello with a templates directory inside it:
mkdir -p flask-hello/templatescd flask-helloSave the following five files with exactly these names and locations.
requirements.txt — dependencies:
Flask==3.1.2gunicorn==23.0.0app.py — the home page handler:
import os
from flask import Flask, render_template, request
app = Flask(__name__)
@app.get("/")def index(): # Посетительские данные передаём шаблону: он экранирует их перед выводом в HTML. return render_template( "index.html", title=os.environ.get("APP_TITLE", "Hello from WebShield!"), name=request.args.get("name", "world"), )templates/index.html — the page and form:
<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>{{ title }}</title><h1>{{ title }}</h1><p>Hello, {{ name }}!</p><form method="get"> <label>Your name <input name="name" maxlength="100" required></label> <button type="submit">Say hello</button></form></html>The name is passed to the template as a value. Quotes and HTML markup are escaped, so visitors cannot turn a greeting into executable code.
gunicorn.conf.py — server settings:
import os
bind = "0.0.0.0:" + os.environ.get("PORT", "8080")workers = 1accesslog = "-"errorlog = "-"The server listens on the port provided by the platform and sends requests and errors to the logs. We use Gunicorn to serve the published app.
railpack.json — the command to run after deployment:
{ "$schema": "https://schema.railpack.com", "deploy": { "startCommand": "gunicorn app:app" }}app:app means the app object in app.py. Dependencies are installed from
requirements.txt during the build; this example needs no Dockerfile.
3. Check the app on your computer
Section titled “3. Check the app on your computer”Run these commands inside flask-hello:
python3 -m venv .venv. .venv/bin/activatepython -m pip install -r requirements.txtgunicorn app:appOpen http://localhost:8080/. You should see a greeting and a name field. Enter
Alice & Bob: the page will display those characters as text. Stop the server
with Ctrl+C.
4. Prepare the upload
Section titled “4. Prepare the upload”Create .webshieldignore to keep local dependencies and secrets out of the archive:
.venv/venv/__pycache__/*.pyc.env.env.*Alongside it, save webshield.toml with the names from step one:
[app]project = "hello"name = "web"Install the command-line client, then check that it has the command:
webshield apps --helpIn the hello project, open Access and issue a Token for CI. It can deploy code only to this
project and read its logs. Copy it, then run:
webshield auth loginPaste the token at the CLI prompt. Keep it out of the app’s files.
5. Publish the code
Section titled “5. Publish the code”From the flask-hello directory, run:
webshield apps deployThe CLI uploads the source and waits for the result. In the panel’s Deployments tab, the new entry moves through Queued → Building → Starting → Live. The first build can take several minutes. If it fails, open Build log for that entry.
6. Connect an address
Section titled “6. Connect an address”In the app’s Hostnames tab, add app.example.com, replacing it with your own name.
If the domain is not in your account yet, connect it first.
- If WebShield hosts the domain’s DNS, wait for the record and certificate to be created.
- If you keep DNS with another provider, add the displayed records following the connection without changing nameservers guide.
Open https://app.example.com/. Your address should show the same form as the local
check. Choose an unused hostname: attaching it changes where its requests go.
7. Update the page and roll back
Section titled “7. Update the page and roll back”In templates/index.html, change the button text from Say hello to
Send a greeting. Run webshield apps deploy again. Once the deployment is
Live, reload the page: the button text will change.
Now open Deployments in the panel and click Roll back to this on the first successful entry. Wait for it to finish: the button will say Say hello again. Rolling back changes the running version; the file on your computer stays as edited.
Verify
Section titled “Verify”Open the published page, submit a name, then check the logs:
webshield apps logsYou should see requests to / with status 200. Entries can take a little time to
arrive: if the log is empty immediately after startup, run the command again in a minute.
To check escaping, open
https://app.example.com/?name=Alice%20%26%20Bob: the page will display Alice & Bob.
Entering <script>alert(1)</script> should either be blocked by protection or displayed
as text, without executing. The app’s escaping also works with bot protection disabled.
To try environment variables, open Environment variables, set APP_TITLE to
My first app, then click Redeploy on the active deployment.
The page heading will change once it completes.
When you finish, revoke the tutorial token in the project’s Token for CI section. Then detach the hostname in Hostnames, delete the tutorial app and the empty project. While the app is running, its resources are metered under usage billing.
If it does not work
Section titled “If it does not work”| Symptom | Cause and fix |
|---|---|
The CLI does not recognize apps |
Your version is old. Update it using the installation instructions. |
The CLI cannot find the app or returns 403 |
Check the names in webshield.toml and that the token belongs to project hello. |
| The build fails | Open Build log. Check file names and dependencies, and upload the directory containing app.py and requirements.txt. |
Startup does not finish or the address returns 502 |
Check Logs, the gunicorn app:app command and gunicorn.conf.py: its port must match the app’s setting. |
| Your address has no HTTPS or shows the previous site | Check the hostname status, DNS records and certificate in Hostnames. |
| A variable changed but the heading did not | After saving the variable, click Redeploy on the active deployment. |
If the previous version responds but the new one stays Starting for a long time with no errors in the log, contact support with the project, app and deployment number.
Next steps
Section titled “Next steps”- Apps — settings, sleep, logs and billing.
- Postgres database — keep data across restarts.
- Deploy from a private repository — publish on every push.