websocket extension unable to connect #1231
-
Hello, I was experimenting with a chat application with websocket. The older <div hx-ws="connect:/chat/{{ slug }}/">
<form hx-ws="send:submit">
<input name="message">
<input type="submit">
</form>
</div> The above code works and is able to connect to the websocket as indicated with the server logs and even the messages. But by using the web socket extension, the connection is never made. <div hx-ext="ws" ws-connect="/chat/{{ slug }}/">
<form ws-send>
<input name="message">
</form>
</div> I tried a lot of combinations with submit attributes, entire URLs, and even changing versions. I am using Django v4.1, channels with daphne (4.0) and htmx version 1.8.5. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I'm having the same issue. I get a websocket connection with hx-ws="connect:ws://127.0.0.1:8000/chat" but no connection with hx-ext="ws" ws-connect="ws://127.0.0.1:8000/chat" |
Beta Was this translation helpful? Give feedback.
Thanks! It worked.
I'm... confused 😆
This works just fine in my case in your project.
Note I omitted
hx-ext="ws"
here since you already define it on your body, which would otherwise simply cause the messages to appear twice when writing in the chat but would still work.I opened 2 tabs, I correctly get messages on both of them...
Could you please make sure that you are including the extension script as per the documentation when trying to use the extension?
I had to add the script here ofc but I don't know if that's because you had reverted to the legacy attribute, or if you had omitt…