{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 自动索引页面\n", "使用 `@ui.page` 装饰器创建的页面是“私有”的。它们的内容会为每个客户端重新创建。因此,当浏览器重新加载页面时,私人页面上显示的 ID 会发生变化。\n", "\n", "未包裹在装饰过的页面函数中的UI元素被放置在根路由\"/\"处的自动生成的索引页面上。这个自动索引页面在启动时创建一次,并被所有可能连接的客户端共享。因此,每个连接的客户端将看到相同的元素。在右侧的演示中,当浏览器重新加载页面时,自动索引页面上显示的 ID 保持不变。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "from uuid import uuid4\n", "\n", "@ui.page('/private_page')\n", "async def private_page():\n", " ui.label(f'private page with ID {uuid4()}')\n", "\n", "ui.label(f'shared auto-index page with ID {uuid4()}')\n", "ui.link('private page', private_page)\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }