|
131 | 131 | { |
132 | 132 | "data": { |
133 | 133 | "text/plain": [ |
134 | | - "datetime.datetime(2024, 12, 10, 14, 0)" |
| 134 | + "datetime.datetime(2024, 12, 14, 14, 0)" |
135 | 135 | ] |
136 | 136 | }, |
137 | 137 | "execution_count": null, |
|
1085 | 1085 | " hdr_tags = 'title','meta','link','style','base'\n", |
1086 | 1086 | " heads,bdy = partition(resp, lambda o: getattr(o, 'tag', '') in hdr_tags)\n", |
1087 | 1087 | " if resp and 'hx-request' not in req.headers and not any(getattr(o, 'tag', '')=='html' for o in resp):\n", |
1088 | | - " resp = respond(req, heads or [Title(req.app.title)], bdy)\n", |
| 1088 | + " title = [] if any(getattr(o, 'tag', '')=='title' for o in heads) else [Title(req.app.title)]\n", |
| 1089 | + " resp = respond(req, [*heads, *title], bdy)\n", |
1089 | 1090 | " return _to_xml(req, resp, indent=fh_cfg.indent), http_hdrs, ts" |
1090 | 1091 | ] |
1091 | 1092 | }, |
|
1229 | 1230 | { |
1230 | 1231 | "data": { |
1231 | 1232 | "text/plain": [ |
1232 | | - "'7eb16e0e-f1b9-4266-98fa-2d84c34f86fc'" |
| 1233 | + "'af1b5dfe-6a32-4348-b1de-692f979f20fb'" |
1233 | 1234 | ] |
1234 | 1235 | }, |
1235 | 1236 | "execution_count": null, |
|
1667 | 1668 | "app,cli,rt = get_cli(FastHTML(secret_key='soopersecret'))" |
1668 | 1669 | ] |
1669 | 1670 | }, |
| 1671 | + { |
| 1672 | + "cell_type": "code", |
| 1673 | + "execution_count": null, |
| 1674 | + "id": "421262a8", |
| 1675 | + "metadata": {}, |
| 1676 | + "outputs": [ |
| 1677 | + { |
| 1678 | + "name": "stdout", |
| 1679 | + "output_type": "stream", |
| 1680 | + "text": [ |
| 1681 | + "[Route(path='/foo', name='foo', methods=['GET', 'HEAD'])]\n" |
| 1682 | + ] |
| 1683 | + }, |
| 1684 | + { |
| 1685 | + "data": { |
| 1686 | + "text/plain": [ |
| 1687 | + "'/foo?param=value'" |
| 1688 | + ] |
| 1689 | + }, |
| 1690 | + "execution_count": null, |
| 1691 | + "metadata": {}, |
| 1692 | + "output_type": "execute_result" |
| 1693 | + } |
| 1694 | + ], |
| 1695 | + "source": [ |
| 1696 | + "app,cli,rt = get_cli(FastHTML(title=\"My Custom Title\"))\n", |
| 1697 | + "@app.get\n", |
| 1698 | + "def foo(): return Div(\"Hello World\")\n", |
| 1699 | + "\n", |
| 1700 | + "print(app.routes)\n", |
| 1701 | + "\n", |
| 1702 | + "response = cli.get('/foo')\n", |
| 1703 | + "assert '<title>My Custom Title</title>' in response.text\n", |
| 1704 | + "\n", |
| 1705 | + "foo.to(param='value')" |
| 1706 | + ] |
| 1707 | + }, |
| 1708 | + { |
| 1709 | + "cell_type": "code", |
| 1710 | + "execution_count": null, |
| 1711 | + "id": "2ebd6270", |
| 1712 | + "metadata": {}, |
| 1713 | + "outputs": [], |
| 1714 | + "source": [ |
| 1715 | + "app,cli,rt = get_cli(FastHTML())\n", |
| 1716 | + "\n", |
| 1717 | + "@rt('/xt2')\n", |
| 1718 | + "def get(): return H1('bar')\n", |
| 1719 | + "\n", |
| 1720 | + "txt = cli.get('/xt2').text\n", |
| 1721 | + "assert '<title>FastHTML page</title>' in txt and '<h1>bar</h1>' in txt and '<html>' in txt" |
| 1722 | + ] |
| 1723 | + }, |
1670 | 1724 | { |
1671 | 1725 | "cell_type": "code", |
1672 | 1726 | "execution_count": null, |
|
2424 | 2478 | "name": "stdout", |
2425 | 2479 | "output_type": "stream", |
2426 | 2480 | "text": [ |
2427 | | - "Set to 2024-12-10 09:54:42.331681\n" |
| 2481 | + "Set to 2024-12-14 12:38:57.886589\n" |
2428 | 2482 | ] |
2429 | 2483 | }, |
2430 | 2484 | { |
2431 | 2485 | "data": { |
2432 | 2486 | "text/plain": [ |
2433 | | - "'Session time: 2024-12-10 09:54:42.331681'" |
| 2487 | + "'Session time: 2024-12-14 12:38:57.886589'" |
2434 | 2488 | ] |
2435 | 2489 | }, |
2436 | 2490 | "execution_count": null, |
|
2950 | 3004 | { |
2951 | 3005 | "data": { |
2952 | 3006 | "text/plain": [ |
2953 | | - "'Cookie was set at time 09:54:43.255286'" |
| 3007 | + "'Cookie was set at time 12:38:58.050326'" |
2954 | 3008 | ] |
2955 | 3009 | }, |
2956 | 3010 | "execution_count": null, |
|
0 commit comments