0

my python code:

import flet as ft
import os


# set Flet path to an empty string to serve at the root URL (e.g., https://lizards.ai/)
# or a folder/path to serve beneath the root (e.g., https://lizards.ai/ui/path
DEFAULT_FLET_PATH = 'http:/ip/'  # or 'ui/path'
DEFAULT_FLET_PORT = 8502


def main(page: ft.Page):
    page.title = "You Enjoy Mychatbot"
    page.add(ft.Text("Reba put a stopper in the bottom of the tub"))


if __name__ == "__main__":
    flet_path = os.getenv("FLET_PATH", DEFAULT_FLET_PATH)
    flet_port = int(os.getenv("FLET_PORT", DEFAULT_FLET_PORT))
    ft.app(name=flet_path, target=main, view=None, port=flet_port)

When I load the web app after showing the Flet icon, it gets stuck on "Please wait for the app to start"

enter image description here

AlexK
  • 2,855
  • 9
  • 16
  • 27

2 Answers2

0

The flet_path provided as the name argument is meant to be a path beneath the root, bearing in mind that flet's default URL strategy uses a hash as root. So, for example, if you provide test/path as the DEFAULT_FLET_PATH in your code above, then run the code locally, it should load at http://localhost:8502/test/path/#/ You've provided http:/ip/ as a path but I think that is likely generating some error that is getting swallowed since a colon is invalid as part of a URL path.

britzkopf
  • 168
  • 1
  • 8
  • This is a correct answer... but if you have the web app on https://example.com and purposely go to https://example.com/something suddenly all your pictures will not load, because it will think its root domain is https://example.com/something. Not sure how to handle that except with nginx redirect to / but you need to exclude a bunch of stuff from that rule etc... – VladoPortos Apr 29 '23 at 07:40
0
DEFAULT_FLET_PATH = ''
DEFAULT_FLET_PORT = 8502

def main(page: ft.Page):
    page.title = "Flet is Working"
    page.vertical_alignment = ft.MainAxisAlignment.CENTER

    txt_number = ft.TextField(value="0", text_align=ft.TextAlign.RIGHT, width=100)

    def minus_click(e):
        txt_number.value = str(int(txt_number.value) - 1)
        page.update()

    def plus_click(e):
        txt_number.value = str(int(txt_number.value) + 1)
        page.update()

    page.add(
          ft.Row(
            [
                 ft.IconButton(ft.icons.REMOVE, on_click=minus_click),
                 txt_number,
                 ft.IconButton(ft.icons.ADD, on_click=plus_click),
            ],
            alignment=ft.MainAxisAlignment.END,
              )
            )

if __name__ == "__main__":
    #flet_path = os.getenv("FLET_PATH", DEFAULT_FLET_PATH)
    flet_path ='app'
    flet_port = int(os.getenv("FLET_PORT", DEFAULT_FLET_PORT))
    ft.app(name=flet_path, target=main, view=None, port=flet_port)

DEFAULT_FLET_PATH = 'http:/ip/'

don't try to specify the ip address, because your app must be running on local interface (you can test it open the port 8502 in your firewall and try connect to http://ip:port). Nginx serve your webapp as a reverse proxy like django app.-

Nginx for flet app config file:

server {
listen 80;
listen 443;
server_name ip or domain;

location = /favicon.ico { access_log off; log_not_found off; }

location / {
    proxy_pass         http://127.0.0.1:8502/;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
    }

location /ws {
    proxy_pass         http://127.0.0.1:8502/ws;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
         }
    }

if is all is rigth you can access by:

http://ip/app

I hope help you!

Franco
  • 1
  • 1