Skip to content

baidule/channels-example

 
 

Repository files navigation

Django Channels Example Build Status

This is an example app demonstrating how to use (and deploy) Django Channels. It's a simple real-time chat app — like a very, very light-weight Slack. There are a bunch of rooms, and everyone in the same room can chat, in real-time, with each other (using WebSockets).

For a walkthrough of what's going on here, see my article over on the Heroku blog.

You can visit my deployment of the example online, or deploy your own copy to Heroku with this button (which requires a free Heroku account):

Deploy

Running locally

To run this app locally, you'll need Python, Postgres, and Redis. (On my Mac, I installed Postgres.app and Redis from Homebrew (brew install redis).)

Then, to run:

  • Install requirements: pip install -r requirements.txt (you almost certainly want to do this in a virtualenv).
  • Migrate: DATABASE_URL=postgres:///... python manage.py migrate
  • If you use heroku local, or foreman/forego, edit .env to add DATABASE_URL and REDIS_URL, then start heroku local/foreman/forego.
  • Or, to run locally with runserver, set DATABASE_URL and REDIS_URL in your environ, then run python manage.py runserver.
  • Or, to run locally with multiple proceses by setting the environ, then running the two commands (daphne and runworker) as shown in the Procfile.

Running with Docker

Tomas Tomecek put together a Dockerized version of this app.

About

django Channels的例子,取代了Django中的“guts”请求响应周期发送跨通道的消息。Channels允许Django以非常类似于传统HTTP的方式支持WebSockets。也允许在运行Django的服务器上运行后台任务。HTTP请求表现以前一样,但也通过Channels进行路由。因此,在Channels支持下Django现在看起来像这样:Channels基本上就是任务队列:消息被生产商推到通道,然后传递给监听通道的消费者之一。如果你使用Go语言中的渠道,这个概念应该相当熟悉。主要的区别在于,DjangoChannels通过网络工作,使生产者和消费者透明地运行在多台机器上。这个网络层称为通道层。通道设计时使用Redis作为其首选通道层,虽然也支持其他类型(和API来创建…

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 76.6%
  • HTML 17.1%
  • JavaScript 5.3%
  • CSS 1.0%