⚠ The htmx script tag in the header should not have the defer attribute, as the htmx extension requires it to be loaded beforehand and depends on it. The defer attribute means the script is executed only after the HTML document has been fully parsed. In the base.html file get rid of the "defer" in , so just
I am trying to create a click game like mobwars or like mafia wars used to be.. how do i make a clan chat where members of a clan only chat with the clan and they auto join when logged in ??
Do you generate html for each user in group ? As I understood you call group_send and for each user in group apllies logic from message_handler, isn't it ?
For some things hyperscript is fantastic like resetting the input field, for other things, especially when there is more logic involved, it is harder to use. Also hyperscript is still young, so there are not many resources available.
Your video was good. But I have few doubts. 1) when I am using WiFi may be some time loss connection on that time. ws protocol was not able to communicate through server from client end. In this case what is your opinion.
You can implement logic in your HTMX views to handle reconnection attempts. This could involve detecting when the connection is lost and automatically attempting to reconnect to the WebSocket server using JavaScript. You can use the onerror event handler of the WebSocket object to detect connection errors and trigger reconnection attempts.
thank you for your great video. But while I was following along with you until minute 10, I encountered a problem where I couldn't connect to the websocket. How should I fix this?
@@ajudmeister Hii, first of all this is such an informative series, I have learnt till now. Everything was working properly untill I tried to set the websocket connection. It didnt work for some reason even after following each step. Its not completing the handshake, htmx is installled, routing is good. I have checked so many times, couldnt find any spelling mistake anyways. Can I contact you by mail or somewhere as I have been stuck here since 3 days :
@@ajudmeister I get now why some people encountered a problem. It stems from django starter assets repo. Url for htmx in base.html contains different url and defer.
TypeError: Group name must be a valid unicode string with length < 100 containing only ASCII alphanumerics, hyphens, underscores, or periods, not demo my group name is demo still showing this error what may be the reason
Somehow your htmx call doesn’t work. It’s saved in the database, that’s why when you reload you see it, it just doesn’t send the message straight back. Maybe a typo somewhere? You can also send me the code then I can have a look
@@syedadilfazal6588 I will look into the Restframework in a future tutorial, but you would need to rewrite the functions to work with APIs. Maybe there are tools out there which can do that for you.
does your website not work at all with Daphne? There might be some configurations issues then. But if you just don't see the code changes you have made, you need to restart the server. Daphne doesn't support automatic code reloading like Django's development server does.
I mean handling multiple user types. For example: A django project for a school that deals with different types of users and their roles. [Admin, Teacher, Parent, Student]. Each user type has very specific roles that they can perform. I hope I am able to put this into words. Best Regards ❤
I might build a project around it but no plans so far. One way to do this is to create individual tables for different roles so they can have unique properties. Then you can apply selected permissions and authentication to them. Django also allows you to group people together in Groups based on their roles and with specific permissions. It really depends on the project what the best approach would be.
@@SpeedCodes-oc7ed I haven't tried Alpine AJAX yet, but from what I understand it returns Jason, not html. I still prefer htmx as the syntax is very simple to use and with the html response you get it integrates seamlessly into a Django project. But if you prefer a Jason response then Alpine AJAX is a great option and is super lightweight if you are already using Alpine JS.
Install asgi server, add server to installed apps, change to asgi application, add the websocket connection in your asgi.py file. See instructions in the video
⚠ The htmx script tag in the header should not have the defer attribute, as the htmx extension requires it to be loaded beforehand and depends on it. The defer attribute means the script is executed only after the HTML document has been fully parsed.
In the base.html file get rid of the "defer" in , so just
dude, there's nothing I can't say but you are AMAZING!
Thanks 😊
Wow great stuff! HTMX really shines here. Amazing stuff Andreas!
Yea htmx makes it very simple and straightforward. Thank you
Danke!
Danke 😊
Excellent stuff, it really helps me a lot, thx
I am trying to create a click game like mobwars or like mafia wars used to be.. how do i make a clan chat where members of a clan only chat with the clan and they auto join when logged in ??
Check out the Group Chat tutorial: ua-cam.com/video/mfpzFemewDQ/v-deo.html.
Do you generate html for each user in group ? As I understood you call group_send and for each user in group apllies logic from message_handler, isn't it ?
Yes exactly. The group_send sends the same event to all members in the group, and the message_handler renders a individual code partial for each user.
Amazing stack, thanks for your dedication! I wonder if Hyperscript can be used instead of JS sprinkle...
For some things hyperscript is fantastic like resetting the input field, for other things, especially when there is more logic involved, it is harder to use. Also hyperscript is still young, so there are not many resources available.
Your video was good. But I have few doubts.
1) when I am using WiFi may be some time loss connection on that time. ws protocol was not able to communicate through server from client end. In this case what is your opinion.
How to handle this situation
You can implement logic in your HTMX views to handle reconnection attempts. This could involve detecting when the connection is lost and automatically attempting to reconnect to the WebSocket server using JavaScript. You can use the onerror event handler of the WebSocket object to detect connection errors and trigger reconnection attempts.
thank you for your great video. But while I was following along with you until minute 10, I encountered a problem where I couldn't connect to the websocket. How should I fix this?
So you don’t get the handshake? Is htmx installed? Is the routing set up correctly? The problem could also be from a spelling mistake somewhere
@@ajudmeister Thank you for your response. I have encountered a problem. I put 'defer' with htmx.js .... 🥲🥲
@@ajudmeister Hii, first of all this is such an informative series, I have learnt till now. Everything was working properly untill I tried to set the websocket connection. It didnt work for some reason even after following each step. Its not completing the handshake, htmx is installled, routing is good. I have checked so many times, couldnt find any spelling mistake anyways. Can I contact you by mail or somewhere as I have been stuck here since 3 days :
@@Qubit-sj6qo yes sure, send me the code pieces you have to ajudmeister@gmail.com then I can have a look .
@@ajudmeister I get now why some people encountered a problem. It stems from django starter assets repo. Url for htmx in base.html contains different url and defer.
if am using react as frontend which extension do i need to use??
i have seen lot of packages in npm for it.
Hi, you can use WebSocket API directly in React to communicate with Django Channels, or the react-websocket package.
Thanks for this😁
do you have any community or other platform to interact with you??
@@ashinrajm9209 I am not connected to any community or platform
TypeError: Group name must be a valid unicode string with length < 100 containing only ASCII alphanumerics, hyphens, underscores, or periods, not demo
my group name is demo still showing this error what may be the reason
@@kailasvs73 Maybe you are not adding it as a string with quotes: “demo” ?
@@ajudmeister its solved actually iam passing chatroom id instead of chatroom name
thanks for revert
Mine stayed in that I have to reload the page for it to send the message. I don't know where I might have gone wrong
I'm stuck at minute 15:10
Somehow your htmx call doesn’t work. It’s saved in the database, that’s why when you reload you see it, it just doesn’t send the message straight back. Maybe a typo somewhere? You can also send me the code then I can have a look
How do we implement a Restframework on it , I want to integrate it with a react native frontend
@@syedadilfazal6588 I will look into the Restframework in a future tutorial, but you would need to rewrite the functions to work with APIs. Maybe there are tools out there which can do that for you.
@ Yeah I am trying on that thanks . And will be waiting for the tutorial with Restframework
my http server not working when iam using daphne server if i use daphne server seprate terminal it doesnot relode the code changes
does your website not work at all with Daphne? There might be some configurations issues then. But if you just don't see the code changes you have made, you need to restart the server. Daphne doesn't support automatic code reloading like Django's development server does.
will there be similar videos about django-channels-restframework?
Yes, coming in future
I love it
For some reason, after sending a message, it is duplicated under the previous ones, although one message is created in the database
Hmm, does this happen before implementing the channel layer?
@@ajudmeister I already fixed it, thanks, I made a mistake in the templates
@@kaizer3937what kind of mistake? I have the same issue
@@overarchingenigma For me it was in consumers.py in receive method. I deleted self.send and other stuff that was already in message_handler
thanks Andres 😽
good thank you
Great ✅✅✅
Do you ❤ plan to upload video about multiple user roles example: [ teacher, admin, student, parent ].
Do you mean different chatrooms for specific user groups?
I mean handling multiple user types.
For example:
A django project for a school that deals with different types of users and their roles. [Admin, Teacher, Parent, Student].
Each user type has very specific roles that they can perform.
I hope I am able to put this into words.
Best Regards ❤
I might build a project around it but no plans so far. One way to do this is to create individual tables for different roles so they can have unique properties. Then you can apply selected permissions and authentication to them. Django also allows you to group people together in Groups based on their roles and with specific permissions. It really depends on the project what the best approach would be.
thats amazing :D
Thank you!
@@ajudmeister Mr Jud what do you prefer alpine ajax or htmx? and why?
@@SpeedCodes-oc7ed I haven't tried Alpine AJAX yet, but from what I understand it returns Jason, not html. I still prefer htmx as the syntax is very simple to use and with the html response you get it integrates seamlessly into a Django project. But if you prefer a Jason response then Alpine AJAX is a great option and is super lightweight if you are already using Alpine JS.
Can you please just tell me how to connect websocket with django
Install asgi server, add server to installed apps, change to asgi application, add the websocket connection in your asgi.py file. See instructions in the video