Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Deploying Django Channels

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Deploying asgi alongside wsgi on Heroku

Hi, Kenneth Love !

Unfortunately, the docs dont cover this topic enough for me to understand.

I want to deploy a project with Channels, working only with one model. So it seems like I need to setup two web dynos for Heroku. One regular, and one with Daphne. Right?

Procfile:

web: gunicorn --pythonpath social-team-builder social_team_builder.deploy --log-file -
web2: daphne social_team_builder.asgi:channel_layer --port $PORT --bind 0.0.0.0 -v2
worker: python manage.py runworker -v2

deploy.py:

import os

from whitenoise.django import DjangoWhiteNoise

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "social_team_builder.deploy_settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

asgi.py:

import os
from channels.asgi import get_channel_layer

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "social_team_builder.deploy_settings")

channel_layer = get_channel_layer()

After installing Heroku Redis in heroku dashboard REDIS_URL appeared in dashboard/settings/config vars. I used it in settings.py:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('redis://h:p2e6672095a593aa48b89635437f7ff478cea12cbd6996b45b33cf84ea418d6d0@ec2-34-249-251-118.eu-west-1.compute.amazonaws.com', 25199)],
        },
        'ROUTING': 'blog_channels.routing.channel_routing',
    },
}

Am I on the right way? I can not run three Dynos for free, so I want to check everything twice. Would appreciate any help.

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You shouldn't need three dynos. It should be two: one for web and one for Daphne (you could run all of the site through Daphne, IIRC, but it might have some processing bottlenecks). Heroku Redis is a service like Heroku Postgres and doesn't count as a dyno.