diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0a949b..068ec512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ + ## 0.3.2 ### New Features diff --git a/fasthtml/core.py b/fasthtml/core.py index 701b955b..f635ba77 100644 --- a/fasthtml/core.py +++ b/fasthtml/core.py @@ -409,8 +409,12 @@ def __init__(self, debug=False, routes=None, middleware=None, exception_handlers def route(self, path:str, methods=None, name=None, include_in_schema=True): "Add a route at `path`; the function name is the default method" def f(func): - m = [methods] if isinstance(methods,str) else [func.__name__] if not methods else methods - self.router.add_route(path, func, methods=m, name=name, include_in_schema=include_in_schema) + n = name + if methods: + m = [methods] if isinstance(methods,str) else methods + if not n: n = func.__name__ + else: m = [func.__name__] + self.router.add_route(path, func, methods=m, name=n, include_in_schema=include_in_schema) return func return f diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb index 3c52e22e..84e465a9 100644 --- a/nbs/api/00_core.ipynb +++ b/nbs/api/00_core.ipynb @@ -1168,8 +1168,12 @@ " def route(self, path:str, methods=None, name=None, include_in_schema=True):\n", " \"Add a route at `path`; the function name is the default method\"\n", " def f(func):\n", - " m = [methods] if isinstance(methods,str) else [func.__name__] if not methods else methods\n", - " self.router.add_route(path, func, methods=m, name=name, include_in_schema=include_in_schema)\n", + " n = name\n", + " if methods:\n", + " m = [methods] if isinstance(methods,str) else methods\n", + " if not n: n = func.__name__\n", + " else: m = [func.__name__]\n", + " self.router.add_route(path, func, methods=m, name=n, include_in_schema=include_in_schema)\n", " return func\n", " return f\n", "\n", @@ -1384,6 +1388,30 @@ "cli.get('/user/Alexis').text" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "54266599", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'http://testserver/user/Alexis; http://testserver/'" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "@rt('/link')\n", + "def get(req): return f\"{req.url_for('gday', nm='Alexis')}; {req.url_for('show_host')}\"\n", + "\n", + "cli.get('/link').text" + ] + }, { "cell_type": "code", "execution_count": null, @@ -1689,7 +1717,7 @@ { "data": { "text/plain": [ - "'Cookie was set at time 05:17:05.477355'" + "'Cookie was set at time 07:51:08.366446'" ] }, "execution_count": null, @@ -1730,7 +1758,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Set to 2024-08-12 05:17:05.526551\n" + "Set to 2024-08-12 07:51:08.415948\n" ] }, { @@ -1764,11 +1792,12 @@ "\n", "\n", "\n", + "\n", "## 0.3.2\n", "\n", "### New Features\n", "\n", - "- generic l\n" + "- generic \n" ] } ], @@ -1796,11 +1825,12 @@ "\n", "\n", "\n", + "\n", "## 0.3.2\n", "\n", "### New Features\n", "\n", - "- generic l\n" + "- generic \n" ] } ],