How to locate websocketbridge.js in Django using channels websocket?

对着背影说爱祢 提交于 2019-12-11 04:21:39

问题


I am trying to implement websockets using channels in Django project. I am getting 404 for webscoketbridge.js Below is html template. {% load staticfiles %} {% block title %}Delivery{% endblock %}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href='https://fonts.googleapis.com/css?family=Satisfy' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="{% static 'channels/js/websocketbridge.js' %}" type="text/javascript"></script>

Also, I tried to have a look in the virtualenv/lib/python3.5/site-packages/channels path, there is no js folder or any file named websocketbridge.js

Has anyone solved this issue?


回答1:


The javascript bridge was removed in v2.1.4. Here's the commit: https://github.com/django/channels/commit/2a9d764ad03927581aa2bfcadccc3e953949cb98#diff-b582cbb2f8294afa8bbe26c4c360a01d

This bit me, in my book that breaks semantic versioning.




回答2:


As the way @tobyspark said, javascript wrapper has been completely removed in the django-channels 2. You can read more on how the js websocket wrapper was working in channels 1 here.

the simplest workaround to clear that error in your browser create a file called websocketbridge.js in the path shown in the error, "static/channels/js/", or you can specify any other path in your HTML src attribute matching the location of the static files and then add the code from here.

But you have to find a better implementation. You can use ReconnectingWebSocket. In the channels 2 release documentation, it is stated there might be other third-party packages for the binding but I don't know any other.



来源:https://stackoverflow.com/questions/53468845/how-to-locate-websocketbridge-js-in-django-using-channels-websocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!