compmonks
compmonks

Reputation: 657

django-channels websocketbridge error

I am pretty new to django-channels. while trying to set websocketbridge I ran into an errorin my JS:

Uncaught ReferenceError: channels is not defined

I loaded websocketbridge.js on top of my html template:

% load staticfiles %}
{% static "channels/js/websocketbridge.js" %}

and in my JS I have tried both:

const webSocketBridge = new channels.WebSocketBridge(); // try 1
const webSocketBridge = new WebSocketBridge(); // try 2

which are raising a similar error. What I am missing?

Upvotes: 1

Views: 886

Answers (1)

compmonks
compmonks

Reputation: 657

I solved this one pretty quick but I am leaving a solution for beginners like me who might find themselves into the same problem.

In my case, I am just handling the static files a bit differently so I just changed

{% static "channels/js/websocketbridge.js" %}

on top of my html template to

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

at the bottom of the template body, where I load specific static files and other js scripts.

Hope that helps.

Upvotes: 1

Related Questions