Skip to content

Commit

Permalink
fixes #263
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Aug 11, 2024
1 parent a954d1d commit 30f9080
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- do not remove -->


## 0.3.2

### New Features
Expand Down
8 changes: 6 additions & 2 deletions fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
42 changes: 36 additions & 6 deletions nbs/api/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -1764,11 +1792,12 @@
"\n",
"<!-- do not remove -->\n",
"\n",
"\n",
"## 0.3.2\n",
"\n",
"### New Features\n",
"\n",
"- generic l\n"
"- generic \n"
]
}
],
Expand Down Expand Up @@ -1796,11 +1825,12 @@
"\n",
"<!-- do not remove -->\n",
"\n",
"\n",
"## 0.3.2\n",
"\n",
"### New Features\n",
"\n",
"- generic l\n"
"- generic \n"
]
}
],
Expand Down

0 comments on commit 30f9080

Please sign in to comment.