You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ hide: [navigation]
5
5
6
6
Welcome to Hyperflask! In this getting started guide will cover the basics and create a simple chat app with authentication.
7
7
8
+
The result of this tutorial is available as a git repository at <https://github.com/hyperflask/getting-started>.
9
+
8
10
## Meet Hyperflask
9
11
10
12
Hyperflask is an opiniated full stack rapid web development framework. It uses Python on the backend, powered by the Flask framework and javascript with htmx on the frontend.
@@ -104,6 +106,8 @@ We are going to create a `ChatMessage` component to render one message. In `app/
104
106
105
107
```
106
108
---
109
+
from hyperflask import request
110
+
107
111
def post():
108
112
return {"message": request.form["message"]}
109
113
---
@@ -156,6 +160,7 @@ Modify our component to save messages:
156
160
157
161
```
158
162
---
163
+
from hyperflask import request
159
164
from app.models import db, Message
160
165
161
166
def post():
@@ -202,12 +207,13 @@ Modify the `ChatMessage` component back to its simpler state:
202
207
</{ChatBubble}>
203
208
```
204
209
205
-
Now let's create a new component `PostMessageForm` in `app/components/PostMessageForm.py` that will handle sending messages.
210
+
Now let's create a new component `PostMessageForm` in `app/components/PostMessageForm.jpy` that will handle sending messages.
206
211
207
212
We will also use the a [form](/guides/forms) in this component to easily validate data.
The MercureStream component uses the [htmx SSE extension](https://htmx.org/extensions/sse/) to connect to the sse stream
246
252
247
-
With a total of 33 lines of code, you now have a real-time and persisted chat room!
248
-
249
253
## Adding authentication
250
254
251
-
First, let's install the [hyperflask-auth](https://github.com/hyperflask/hyperflask-auth) extension. In a VS Code terminal (while connected to the dev container), execute `uv add hyperflask-auth`.
255
+
First, let's install the [hyperflask-users](https://github.com/hyperflask/hyperflask-users) extension. In a VS Code terminal (while connected to the dev container), execute `uv add hyperflask-users`.
252
256
253
-
As we will not deal with [database migrations]() during this tutorial, delete your existing database: `rm databases/app.db`.
257
+
As we will not deal with [database migrations](/guides/models) during this tutorial, delete your existing database: `rm databases/app.db`.
254
258
255
259
!!! info
256
-
Hyperflask-Auth provices login and signup pages as well as everything you need for a professional authentication flow.
260
+
Hyperflask-Users provices login and signup pages as well as everything you need for a professional authentication flow and user management.
257
261
258
262
Let's create a user model and change our existing model to be bound to users:
@@ -274,7 +278,7 @@ class Message(UserRelatedMixin, db.Model):
274
278
Modify the component `ChatMessage` to display the author:
275
279
276
280
```
277
-
<{ChatBubble header=props.message.user.username}>
281
+
<{ChatBubble header=props.message.user.email}>
278
282
{{props.message.message|markdown}}
279
283
</{ChatBubble}>
280
284
```
@@ -285,6 +289,10 @@ Finally, add `page.login_required()` at the top of your page frontmatter to requ
285
289
286
290
Signup for an account on Fly.io or any VPS provider (eg: Digital Ocean) then run the following command from a VS Code terminal (while connected to the dev container):
287
291
288
-
hyperflask deploy
292
+
uv run hyperflask deploy
293
+
294
+
Some information will be requested then the deployment will happen automatically. Connect to your domain and voilà!
295
+
296
+
## Going further
289
297
290
-
Some information will be requested then the deployment will happen automatically. Connect to your domain and voilà!
298
+
Checkout the [Github repository](https://github.com/hyperflask/getting-started) with the result of this tutorial and more. It also includes a nice UI, chat rooms, etc...
0 commit comments