You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Middlewares to AddPagesy. which will be automatically integrated into all decorated pages.
To use Middleware in AddPagesy is very easy, you can do it in two ways (both support async):
Function: It only supports the use before request and has as parameter data:fs.Datasy.
Class: It has to be inherited from fs.MiddlewareRequest, which contains two very interesting methods before_request and after_request, you can use the attribute data:fs.Datasy.
Example:
importflet_easyasfsimportfletasftclassCustomMiddleware(fs.MiddlewareRequest):
defbefore_request(self):
print("+ Before request", self.data.page.title)
asyncdefafter_request(self):
print("+ After request")
asyncdefuse_middleware(data: fs.Datasy):
print("+ Use middleware before request", data.history_routes)
tools=fs.AddPagesy(
middlewares=[CustomMiddleware, use_middleware],
)
@tools.page(route="/home", title="Tools-Flet-Easy")asyncdefindex_page(data: fs.Datasy):
returnft.View(
controls=[
ft.Text("Home page"),
]
)
@tools.page(route="/test", title="Test-Flet-Easy")deftest_page(data: fs.Datasy):
returnft.View(
controls=[
ft.Text("Test page"),
]
)
The text was updated successfully, but these errors were encountered:
Function: It only supports the use before request and has as parameter
data:fs.Datasy
.Class: It has to be inherited from fs.MiddlewareRequest, which contains two very interesting methods
before_request
andafter_request
, you can use the attributedata:fs.Datasy
.Example:
The text was updated successfully, but these errors were encountered: