mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2026-03-13 10:32:25 +08:00
update docs
This commit is contained in:
@@ -54,3 +54,11 @@ You can enable site search by add `SearchProvider` to `admin_app.configure(...)`
|
||||
```python
|
||||
await admin_app.configure(providers=[SearchProvider()])
|
||||
```
|
||||
|
||||
## Notification
|
||||
|
||||
You can use notification by adding `NotificationProvider` to `admin_app.configure(...) implement by websocket.
|
||||
|
||||
```python
|
||||
await admin_app.configure(providers=[NotificationProvider()])
|
||||
```
|
||||
|
||||
47
docs/en/docs/reference/notification.md
Normal file
47
docs/en/docs/reference/notification.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Notification (💗 Pro only)
|
||||
|
||||
`FastAPI-Admin` provide a notification center implement by websocket.
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
You should add it to providers to enable it.
|
||||
|
||||
```python
|
||||
from fastapi import FastAPI
|
||||
from fastapi_admin.app import app as admin_app
|
||||
from fastapi_admin.providers.notification import NotificationProvider
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
provider = NotificationProvider()
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
await admin_app.configure(
|
||||
providers=[provider]
|
||||
)
|
||||
```
|
||||
|
||||
There are two ways to send notifications.
|
||||
|
||||
One is call `await provider.broadcast()` directly.
|
||||
|
||||
```python
|
||||
data = {
|
||||
"title": "test",
|
||||
"content": "//avatars.githubusercontent.com/u/13377178?v=4",
|
||||
"image": "https://avatars.githubusercontent.com/u/13377178?v=4"
|
||||
}
|
||||
await provider.broadcast(data)
|
||||
```
|
||||
|
||||
If you want to send notifications out of application, another way is use http api.
|
||||
|
||||
```python
|
||||
import requests
|
||||
|
||||
requests.post('http://localhost:8000/admin/notification', json=data)
|
||||
```
|
||||
@@ -52,6 +52,7 @@ nav:
|
||||
- reference/admin_log.md
|
||||
- reference/global_search.md
|
||||
- reference/errors.md
|
||||
- reference/notification.md
|
||||
- Customization:
|
||||
- custom/page.md
|
||||
- custom/overwrite.md
|
||||
|
||||
Reference in New Issue
Block a user