浏览代码

allow passing arguments when calling the page decorator

Falko Schindler 2 年之前
父节点
当前提交
27220ae8f0
共有 1 个文件被更改,包括 2 次插入2 次删除
  1. 2 2
      nicegui/page.py

+ 2 - 2
nicegui/page.py

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