Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Writing Up the Frontend

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,810 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,810 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..