pythonazure-appserviceazure-webapps

Is it possible to deploy flet app to Azure app service?


I'm trying to deploy sample flet app to Azure from vs code getting Azure default page. Is it possible deploy flet app to Azure if it is how? main.py:

import flet as ft

def main(page: ft.Page):
    page.title = "Counter App"

    text = ft.Text("0", size=30)
    
    def increment(e):
        text.value = str(int(text.value) + 1)
        page.update()

    page.add(
        text,
        ft.ElevatedButton("Increment", on_click=increment)
    )

ft.app(target=main)

Solution

  • I have created a Sample flet app and deployed to Azure App service using vs code.

    To deploy flet app to Azure follow the below steps:

    ft.app(target=main, view=ft.AppView.WEB_BROWSER)
    

    Below is complete code of my main. py file:

    import flet as ft
    def main(page: ft.Page):
       counter = ft.Text("0", size=50, data=0)
       def increment_click(e):
           counter.data += 1
           counter.value = str(counter.data)
           counter.update()
       page.floating_action_button = ft.FloatingActionButton(
           icon=ft.Icons.ADD, on_click=increment_click
       )
       page.add(
           ft.SafeArea(
               ft.Container(
                   counter,
                   alignment=ft.alignment.center,
               ),
               expand=True,
           )
       )
    ft.app(target=main, view=ft.AppView.WEB_BROWSER)
    
    flet publish src/main.py
    

    enter image description here

    enter image description here

    Azure Output:

    enter image description here