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 Writing Up the Frontend

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

How to update to Channels==1.1.3 [SOLVED]

Hi, Kenneth Love !

I'm not sure what is wrong with my code..

composed json looks like this: {"1": "vacant", "2": "filled", "3": "filled"}

template:

{% for position in project_positions %}
<tr>
<td>{{  position }}</td>
<td><span class="js-{{ position.id }}">0</span></td>
</tr>
{% endfor %}

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


<script>
    $(document).ready(function() {
       socket = new WebSocket("ws://" + window.location.host);
       socket.onmessage = function(e) {
           var data = JSON.parse(e.data);
           for (var position in data) {
                   $(".js-"+ position).text(data[position]);
           }
       }
    });
</script>

Template shows "0"s for each. Where is my mistake?

How to solve:

According to docs here:

def ws_connect(message):
    message.reply_channel.send({"accept": True})  # Add this line to get over HANDSHAKING
    Group('buttons').add(message.reply_channel)

without that line Chrome dev tools console would show:

WebSocket connection to 'ws://127.0.0.1:8000/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET

Done!

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The joys of making content on rapidly-evolving projects...

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

Yes, I see.) Another thing is: Channels need pypiwin32 to run on windows.

Right now deploying it on Heroku. Looking up how to set up redis backend..