django - 为什么我的 Django 应用服务器发送事件端点立即关闭?
问题描述
我正在使用来自 Fanout 的 Django 和 django-eventstream 为流数据制作端点。但是每当我连接到端点时,它都会返回数据然后关闭。例如:
http --stream http://127.0.0.1:8000/stream-api/projects/22/feeds/
回复:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 2077
Content-Type: text/event-stream
Date: Fri, 19 Apr 2019 23:57:20 GMT
Grip-Channel: events-project-22; filter=skip-users, user-anonymous; filter=require-sub
Grip-Hold: stream
Grip-Keep-Alive: event: keep-alive\ndata:\n\n; format=cstring; timeout=20
Grip-Link: </stream-api/projects/22/feeds/?link=next&recover=true&es-meta=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlcyIsImV4cCI6MTU1NTcyMTg0MCwiY2hhbm5lbHMiOlsicHJvamVjdC0yMiJdLCJ1c2VyIjoiYW5vbnltb3VzIn0.-30HrkebKMBxw7RWf_QoNnmE1baWIdID3DrHSL58Et4>; rel=next
Grip-Set-Meta: user="anonymous"
Server: WSGIServer/0.2 CPython/3.6.7
Vary: Cookie
X-Frame-Options: SAMEORIGIN
:
event: stream-open
data:
我正在使用 Django 2.2 和 Django-eventstream 进行服务器发送事件。
我的配置。路由.py
from django.conf.urls import url
from channels.routing import URLRouter
from channels.http import AsgiHandler
from channels.auth import AuthMiddlewareStack
import django_eventstream
urlpatterns = [
#url(r'^events/', AuthMiddlewareStack(
# URLRouter(django_eventstream.routing.urlpatterns)
#), {'channels': ['test']}),
url(r'^projects/(?P<project_id>[^/]+)/feeds/', AuthMiddlewareStack(
URLRouter(django_eventstream.routing.urlpatterns)
), {'format-channels': ['project-{project_id}']}),
url(r'', AsgiHandler),
]
网址.py
from django.urls import path, include
import django_eventstream
urlpatterns = [
#path('events/', include(django_eventstream.urls), {'channels': ['test']}),
path('projects/<project_id>/feeds/', include(django_eventstream.urls), {'format-channels': ['project-{project_id}']}),
]
解决方案
推荐阅读
- javascript - 如何将字符串解析为“标题对象”?
- android - 按下主页按钮后,我得到了活动开关 ANDROID
- java - 如何在 java 中获取 timeRangeEndDate 和 timeRangeStartDate?
- angular - 带有父变量的角类型脚本未定义错误
- ios - 如何更改状态栏背景的颜色?
- javascript - 如何在将光标放在文本区域时弹出模式
- python - KeyError:运行 Ansible 剧本时的“用户”
- php - (Laravel) 每次数据库有变化就更新界面?
- mysql - 如果表只包含外键,它可以自动填充吗?
- jsf - 从阶段侦听器(beforePhase 或 afterPhase)访问 adf 中页面片段的 UI 组件