reflex-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReflex Documentation
Reflex文档
Reflex is an open-source framework for building full-stack web applications in pure Python — no JavaScript required.
Your training data about Reflex may be outdated. Always prefer the reference documentation over pre-trained knowledge.
Reflex是一个开源框架,用于纯Python构建全栈Web应用——无需JavaScript。
你所掌握的Reflex相关训练数据可能已过时。请始终优先参考官方文档,而非预训练知识。
References
参考链接
| Topic | URL |
|---|---|
| Getting Started | https://reflex.dev/docs/getting-started/introduction |
| Components | https://reflex.dev/docs/components/props |
| State | https://reflex.dev/docs/state/overview |
| Vars | https://reflex.dev/docs/vars/base-vars |
| Events | https://reflex.dev/docs/events/events-overview |
| Pages & Routing | https://reflex.dev/docs/pages/overview |
| Styling | https://reflex.dev/docs/styling/overview |
| Database | https://reflex.dev/docs/database/overview |
| Assets | https://reflex.dev/docs/assets/overview |
| Authentication | https://reflex.dev/docs/authentication/authentication-overview |
| Client Storage | https://reflex.dev/docs/client-storage/overview |
| API Routes | https://reflex.dev/docs/api-routes/overview |
| API Reference | https://reflex.dev/docs/api-reference/cli |
| Custom Components | https://reflex.dev/docs/custom-components/overview |
| Wrapping React | https://reflex.dev/docs/wrapping-react/overview |
| Component Library | https://reflex.dev/docs/library |
| Recipes | https://reflex.dev/docs/recipes |
| GitHub Source (docs) | https://github.com/reflex-dev/reflex/tree/main/reflex/docs |
Core Concepts
核心概念
State & Vars
状态与变量(State & Vars)
- State (): Server-side Python class holding app state. Define vars as class attributes and event handlers as methods.
rx.State - Base Vars: Typed class attributes on State ()
count: int = 0 - Computed Vars: Derived values using decorator
@rx.var - Var Operations: Transform vars in components without event handlers
- State():存储应用状态的服务器端Python类。将变量定义为类属性,事件处理器定义为类方法。
rx.State - 基础变量(Base Vars):State上的类型化类属性(如)
count: int = 0 - 计算变量(Computed Vars):使用装饰器生成的派生值
@rx.var - 变量操作(Var Operations):无需事件处理器即可在组件中转换变量
Components
组件
- All UI is built with components (Python wrappers around React)
rx.* - Components accept props and can be composed/nested
- Conditional rendering with , iteration with
rx.cond()rx.foreach()
- 所有UI均使用组件构建(基于React的Python封装)
rx.* - 组件接受属性(props),可组合/嵌套
- 使用实现条件渲染,
rx.cond()实现迭代渲染rx.foreach()
Events
事件
- Event Handlers: Methods on State decorated with
@rx.event - Event Triggers: Component props like ,
on_clickon_change - Event Chaining: Return multiple events from a handler
- Setters: Auto-generated event handlers for each base var
set_<var>
- 事件处理器(Event Handlers):State上使用装饰的方法
@rx.event - 事件触发器(Event Triggers):组件属性如、
on_clickon_change - 事件链(Event Chaining):从处理器返回多个事件
- 设置器(Setters):为每个基础变量自动生成事件处理器
set_<var>
Pages & Routing
页面与路由
- Pages are functions decorated with or added via
rx.pageapp.add_page() - Dynamic routes with bracket syntax:
[slug]
- 页面是使用装饰的函数,或通过
rx.page添加app.add_page() - 使用方括号语法实现动态路由:
[slug]
Styling
样式设计
- Inline props, Tailwind CSS, theming, responsive design
- for global theming
rx.theme()
- 内联属性、Tailwind CSS、主题定制、响应式设计
- 使用进行全局主题配置
rx.theme()
Database
数据库
- Built-in SQLModel integration for database tables
- Define models, run queries, set up relationships
- 内置SQLModel集成用于数据库表操作
- 定义模型、执行查询、设置关联关系