pip python django3 websocket
项目描述
Django - WebSocket
MyGitAddressChina
Github
联系我ahriknow@gmail.com
如何使用
-
安装
pip install djangowebsocket
-
更改 的内容
asgi.py,如果您的项目名称是Projectimport os from django.core.asgi import get_asgi_application from djangowebsocket import get_ws_application from djangowebsocket import path, paths, middleware os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Project.settings') http_application = get_asgi_application() websocket_application = get_ws_application() # register your routers, About to support regular matching path('/path1/', ViewClass1) # what is ViewClass, see below # or paths({ '/path2/': ViewClass2, '/path3/': ViewClass3, }) # register your middleware, it's sequential middleware(MiddlewareClass1) # what is MiddlewareClass1, see below # or middlewares([MiddlewareClass2, MiddlewareClass3]) async def branch(scope, receive, send): if scope.get('type') == 'websocket': await websocket_application(scope, receive, send) else: await http_application(scope, receive, send) application = branch
-
编写 ViewClass
from djangowebsocket import BaseWebSocketView, Response class WebSocketView(BaseWebSocketView): def websocket(self, request): # Response's data can be str, dict, list, tuple, etc. return Response({'test': '123'})
-
编写中间件类
from djangowebsocket import BaseMiddleware class MD(BaseMiddleware): def process_request(self, request): print(request.data) # Preprocess request return request def process_response(self, request, response): response.set_data({'111': 222}) # Set data by set_data return response
-
请求有attr:
QUERY # params in path HEADER TYPE ASGI SCHEM SERVER CLIENT ROOT_PATH PATH RAW_PATH SUB_PROTOCOLS
2020.09.22
项目详情
关
djangowebsocket -1.0.1.tar.gz 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 3fa353c87c4dd223d12e7ae2fe07ba5b9d950b933a003bd43687ee89332a8143 |
|
| MD5 | c06480b14239ba74463ae4c2d3073bd8 |
|
| 布莱克2-256 | 785db67fe346a1641536de783c290d150faa7a013b26137f9e3ae234ad1add30 |
关
djangowebsocket -1.0.1-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | f08bf9728ee9ea6acabb19bd2f4b1bc69a9c4d3b9d0fd356902523a0212c6de1 |
|
| MD5 | 4f75d925959e58455347e8f18f5222fa |
|
| 布莱克2-256 | bb137c70e68a3c3570455f1396f31d3bf01b8ee269e510db5bf0fd10e7c6d7ce |