静态文件Django频道

时间:2018-12-31 21:41:14

标签: javascript django websocket django-channels

我的通知系统主页出现问题。我遵循这门课程 https://arunrocks.com/understanding-django-channels/这是我的js代码

    <script src="{% static '/channels/js/websocketbridge.js' %}" type="text/javascript"></script>

 <script>
document.addEventListener('DOMContentLoaded', function() {
  const webSocketBridge = new channels.WebSocketBridge();
  const nl = document.querySelector("#notifylist");

  webSocketBridge.connect('/notifications/');
  webSocketBridge.listen(function(action, stream) {
    console.log("RESPONSE:", action);
    if(action.event == "New User") {
      var el = document.createElement("li");
      el.innerHTML = `New user <b>${action.username}</b> has joined!`;
      nl.appendChild(el);
    }
  })
  document.ws = webSocketBridge; /* for debugging */
})
</script>

在控制台中出现此错误 enter image description here

0 个答案:

没有答案