Cloudflare Hosting

This guide details hosting Flet static websites on Cloudflare Pages.

Prerequisites

  • Cloudflare account (sign up at [dash.cloudflare.com](https://dash.cloudflare.com/sign-up/pages))
  • Email verification
  • Deployment Methods

    1. **Connecting to a Git provider** * **Note:** Works with flet publish command. * Requires GitHub or GitLab account with the repository. * Steps: * Click "Connect to Git" button. * Select Git provider and authorize account. * Choose repository and click "Begin setup". * **Add runtime.txt file to repository:** Specify Python version (e.g., 3.7). * Configure project name and production branch. * **Build Settings:** * Skip "Framework preset". * Set "Build command" based on application structure. * Set "Output directory" to dist (generated by flet publish). * Optionally configure "Root directory" and "Environment variables". * Click "Save and Deploy". * After deployment, click the provided URL to access the site. Allow a minute for setup completion if a Cloudflare error appears.

    2. **Direct Upload** * **Note:** Works with flet build web and flet publish commands. * Steps: * Click "Upload assets". * **Step 1:** Provide a project name. * **Step 2:** Upload project assets as a folder or a zip file. * If assets are not ready, use flet publish to generate a dist folder and upload it. * Click "Deploy site". * A success message with a link to the deployed website is shown. Allow a minute for setup completion if a Cloudflare error appears.

    Troubleshooting

  • **Debugging:**
  • * Use print() statements: Output appears in the browser's Developer Tools Console. * Use the logging module: Output messages with different severities to the Console. * **Enable detailed Flet logging:** Add the following to your program:
            import logging
            logging.basicConfig(level=logging.DEBUG)
            

    Platform Support

  • Web (Static Websites)
  • Related Topics

  • Publish web app as static website
  • Creating an Extension