Modules
A Flask adapter for the RouteLit framework, enabling seamless integration of RouteLit's reactive UI components with Flask web applications.
Source code in src/routelit_flask/adapter.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
__init__(routelit, *, static_path=None, template_path=get_default_template_path(), run_mode='prod', local_frontend_server=None, local_components_server=None, cookie_config=None)
¶
Initialize the RouteLitFlaskAdapter. - When run_mode="prod", no need to specify local_frontend_server and local_components_server. - When run_mode="dev_client", you need to specify local_frontend_server. - When run_mode="dev_components", you need to specify local_components_server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
routelit
|
RouteLit
|
The RouteLit instance. |
required |
static_path
|
Optional[str]
|
The path to the static js/css assets are. |
None
|
template_path
|
str
|
The path to the index.html template file. Default is in routelit package, so no need to specify. |
get_default_template_path()
|
run_mode
|
RunMode
|
The run mode. Example: "prod", "dev_client", "dev_components". |
'prod'
|
local_frontend_server
|
Optional[str]
|
The local vite frontend server. Example: "http://localhost:5173". |
None
|
local_components_server
|
Optional[str]
|
The local vite components server. Example: "http://localhost:5174". |
None
|
cookie_config
|
Optional[dict[str, Any]]
|
The cookie configuration. Default is production cookie config. |
None
|
Source code in src/routelit_flask/adapter.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
configure(flask_app, json_provider_class=None)
¶
Configure the Flask application to use the RouteLitFlaskAdapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flask_app
|
Flask
|
The Flask application to configure. |
required |
json_provider_class
|
Optional[Union[type[JSONProvider], Literal[False]]]
|
The JSON provider class to use. If None, use CustomJSONProvider. If False, do not set a custom JSON provider. |
None
|
Returns:
| Type | Description |
|---|---|
RouteLitFlaskAdapter
|
The RouteLitFlaskAdapter instance. |
Source code in src/routelit_flask/adapter.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
response(view_fn, inject_builder=None, *args, **kwargs)
¶
Handle a request and return a response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_fn
|
ViewFn
|
The view function to handle the request. |
required |
inject_builder
|
Optional[bool]
|
Whether to inject the builder into the request. |
None
|
*args
|
Any
|
Additional arguments to pass to the view function. |
()
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the view function. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
A Flask response. |
Source code in src/routelit_flask/adapter.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
stream_response(view_fn, inject_builder=None, *args, **kwargs)
¶
Handle a request and return a response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_fn
|
ViewFn
|
The view function to handle the request. |
required |
inject_builder
|
Optional[bool]
|
Whether to inject the builder into the request. |
None
|
*args
|
Any
|
Additional arguments to pass to the view function. |
()
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the view function. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
A Flask response. |
Source code in src/routelit_flask/adapter.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
The run mode for the RouteLitFlaskAdapter.
prod: Production mode.dev_client: Development mode for the client.dev_components: Development mode for the components.
Bases: RouteLitRequest
Implements the RouteLitRequest interface for Flask.
Source code in src/routelit_flask/request.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |