Python Chat Tutorial with Django and React

Nick Parsons on May 08, 2019

This tutorial will explain how to build a chat application with Python, Django and React. Unlike other tutorials, Iā€™m not using Python/Django for ... [Read Full]
markdown guide
 

Thanks for putting this together. I was able to complete steps 1-5. When I tried to complete Step 6 I get the following error message:

Error: userToken does not have a user_id or is not matching with user.id
StreamChat.setUser
node_modules/stream-chat/dist/browser.es.js:3186
new App
localhost:3001/static/js/main.chun...

163 | constructor(props) {
164 |   super(props);
165 |   this.client = new stream_chat__WEBPACK_IMPORTED_MODULE_2__["StreamChat"]("<removed>");
> 166 |   this.client.setUser({
167 |     id: "cool-sky-9",
168 |     name: "Cool Sky",
169 |     image: "https://getstream.io/random_svg/?id=cool-sky-9&name=Cool+sky"

Any suggestions on what I might be doing wrong?

 

Same error here.

Error: userToken does not have a user_id or is not matching with user.id

All I changed:

mychat/settings.py on line 47 and 48 => 4tk***, zgbw6*********************************
chat-frontend/src/Chat.js on line 17 => this.client = new StreamChat("60XXX");

 

Happy to help. Any chance your API key is mixed up / not the same between your app and server-side code? This would throw that kind of error.

 

I have the Chat.js and settings.py files updated with the same API key. Is there somewhere else the API key needs to be set that I missed?

 

Thanks for reminding me how easy it is to do APIs with Django! I have an upcoming project that needs an admin frontend, a batch-ish portion, and an API all three; going with Django will make it easy to just get it done.

 
 

At this stage, Django Channels ( WebSocket support ) is more matured and can able to use in production.

 

Django Channels work, but the performance just isn't great. It's a good fit if your app is small. If it grows you'll want to use C++, Java, Elixir or Golang (my favorite) for websockets in order to be cost effective.

 

What benchmarks are you using to determine the performance evaluation?

True, synchronous code running on an internal thread executor on an event loop will be slower than fully async, but still curious.

And which version of channels did you try most recently?

 
 

Have questions? Drop them here! I'm happy to help you out!

 

Cool way to use it as I had problems in using web sockets with Django in the past.

Due to the complexity and rewrite of the libraries with very little tutorial information.

code of conduct - report abuse