Explorar o código

allow passing arguments when calling the page decorator

Falko Schindler %!s(int64=2) %!d(string=hai) anos
pai
achega
27220ae8f0
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      nicegui/page.py

+ 2 - 2
nicegui/page.py

@@ -188,7 +188,7 @@ class page:
         self.page: Optional[Page] = None
         *_, self.converters = compile_path(route)
 
-    def __call__(self, func) -> Callable:
+    def __call__(self, func, **kwargs) -> Callable:
         @wraps(func)
         async def decorated(request: Optional[Request] = None) -> Page:
             self.page = Page(
@@ -209,7 +209,7 @@ class page:
                             raise RuntimeError('Cannot use `request` argument in shared page')
                     await self.connected(request)
                     await self.header()
-                    args = convert_arguments(request, self.converters, func)
+                    args = {**kwargs, **convert_arguments(request, self.converters, func)}
                     result = await func(**args) if is_coroutine(func) else func(**args)
                     if isinstance(result, types.GeneratorType):
                         if self.shared: