Skip to content
WebShield Docs

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.

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.

Create an empty directory called flask-hello with a templates directory inside it:

Terminal window
mkdir -p flask-hello/templates
cd flask-hello

Save the following five files with exactly these names and locations.

requirements.txt — dependencies:

Flask==3.1.2
gunicorn==23.0.0

app.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 = 1
accesslog = "-"
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.

Run these commands inside flask-hello:

Terminal window
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
gunicorn app:app

Open 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.

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:

Terminal window
webshield apps --help

In 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:

Terminal window
webshield auth login

Paste the token at the CLI prompt. Keep it out of the app’s files.

From the flask-hello directory, run:

Terminal window
webshield apps deploy

The 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.

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.

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.

Open the published page, submit a name, then check the logs:

Terminal window
webshield apps logs

You 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.

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.