Ok. Did it work? Did you change the routing.py?
You mean the asgi.py, yes here
"""
ASGI config for MyProject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
import os
import arborchat.routing
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from routing import websocket_urlpatterns
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings')
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
It just says no module name 'arborchat' and unresolved reference 'websocket_urlpatterns
This change actually wasn’t necessary. You can keep it as it was.
You mean the asgi.py, yes here
No. I mean change the code in routing.py as below.
consumers.ChatConsumer.as_asgi)
to
consumers.ChatConsumer.as_asgi())
Yes I did
routings.py
from django.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r'ws/arborchat/(?P<room_name>\w+)/$', consumers.ChatConsumer.as_asgi())
But what about the two errors I showed earlier with my asgi.py?
arborchat is the name of my chat server app.
Try this change
from routing import websocket_urlpatterns
to
from arborchat.routing import websocket_urlpatterns
in asgi.py.
One other thing, are you familiar with Ubuntu?
Little bit. Did it solve the error?
No it didn’t. Besides, it’s not recognizing my arborchat module. I asked because I booted to Ubuntu recently and it’s really laggy and the mouse occasionally stops working. This is brand new HP laptop too
It can’t be problem with ubuntu. It may could be because of, windows, malware, anti virus software, windows updates, virtual machine software etc. Can give a direct reason without more detail.
Yeah could be Windows update. I’ve only had this laptop for a week. It’s got 16 GM Ram and recently added 500GB SSD for storage. I wonder if I didn’t leave enough disk space when I partitioned
Yeah that’s what I thought, Ubuntu or Linux in general typically has no viruses. This computer was really cheap, so it’s probably a hardware issue.
At least the partition that has windows should have 5-20GB. 5GB is enough to do some work, but windows updates may fail and become slow.
So that’s probably what this is, Windows update. I probably need to add some disk space to Windows OS. But back to my original issue
Try removing import arborchat.routing from the asgi.py file.
I removed it
"""
ASGI config for MyProject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""
import os
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application
from arborchat.routing import websocket_urlpatterns
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings')
django_asgi_app = get_asgi_application()
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
What should I do about this line of code?
So I pinpointed the source of the problem, just not sure how to fix it. My asgi.py file isn’t able to import anything from my routing.py file, despite being in the same directory as my arbchat app
Please post a pip list of your virtual environment that you are using for this. I think it’s worth verifying that you are using compatible versions of these different components.
I figured out why I was getting this issue, Redis wasn’t installed. It’s working now. Thank you guys