Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I consume external streams in django #7

Open
burakakca opened this issue Sep 26, 2024 · 3 comments
Open

How can I consume external streams in django #7

burakakca opened this issue Sep 26, 2024 · 3 comments

Comments

@burakakca
Copy link

Hi, I have Rails turbo streams and I want to subscribe from my django project. I Try to create a consumer for that but i didn't succeed. Is there a way to do that? Or I just need to use asyncio websocket client for that?

urlpatterns = [
path("cable", ActionCableConsumer.as_asgi()),
path("external",CustomActionCableConsumer.as_asgi())
]

@michael-yin
Copy link
Member

@burakakca

If you want to use Hotwire Turbo Stream and Websocket to do real-time update.

Please check more details on this link https://django-turbo-helper.readthedocs.io/en/latest/real-time-updates.html

In your code, path("external",CustomActionCableConsumer.as_asgi()) seems not needed.

Thx.

@burakakca
Copy link
Author

burakakca commented Sep 27, 2024

In this doc, If i didn't miss something there two way one of them sse like below, other is actioncable right?

<turbo-stream-source src="http://127.0.0.1:3000/products/stream">
</turbo-stream-source>

But I'm trying to do this with actioncable.

Also I got another problem for {% load turbo_helper %} jinja2 problem do you have idea to fix that?

@michael-yin
Copy link
Member

michael-yin commented Sep 27, 2024

@burakakca

The turbo_stream_from from django-turbo-helper would help generate turbo-stream-source element.

It has custom sign value, so the server side should use from turbo_helper.channels.streams_channel import TurboStreamCableChannel, or the Websocket request would not be processed. (This is for security reason)

As for jinja2 support, I might add the support in the future but now I have other things to do first.

If you do have this requirement, I suggest you to check how Wagtail do this with extension: https://docs.wagtail.org/en/stable/reference/jinja2.html

Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants