{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 参数注入\n", "\n", "多亏了 FastAPI,一个页面函数可以接受可选参数,以提供[路径参数](https://fastapi.tiangolo.com/tutorial/path-params/)、[查询参数](https://fastapi.tiangolo.com/tutorial/query-params/)或整个传入[请求](https://fastapi.tiangolo.com/advanced/using-request-directly/),以便访问主体负载、标头、cookie等。" ] }, { "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", "\n", "@ui.page('/icon/{icon}')\n", "def icons(icon: str, amount: int = 1):\n", " ui.label(icon).classes('text-h3')\n", " with ui.row():\n", " [ui.icon(icon).classes('text-h3') for _ in range(amount)]\n", "ui.link('Star', '/icon/star?amount=5')\n", "ui.link('Home', '/icon/home')\n", "ui.link('Water', '/icon/water_drop?amount=3')\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 }