Advertisement
nefegago

django channels

Sep 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. Error generado al correrlo
  2.  
  3. (src) debian@debian:~/Escritorio/mysite$ python manage.py  runserver
  4. Watching for file changes with StatReloader
  5. Performing system checks...
  6.  
  7. System check identified no issues (0 silenced).
  8. September 17, 2019 - 15:27:14
  9. Django version 2.2.3, using settings 'mysite.settings'
  10. Starting ASGI/Channels version 2.2.0 development server at http://127.0.0.1:8000/
  11. Quit the server with CONTROL-C.
  12. HTTP GET /chat/lobby/ 200 [0.02, 127.0.0.1:46054]
  13. [Failure instance: Traceback: <class 'ValueError'>: No route found for path 'ws/chat/lobby/'.
  14. /home/debian/Escritorio/src/lib/python3.7/site-packages/autobahn/websocket/protocol.py:2844:processHandshake
  15. /home/debian/Escritorio/src/lib/python3.7/site-packages/txaio/tx.py:429:as_future
  16. /home/debian/Escritorio/src/lib/python3.7/site-packages/twisted/internet/defer.py:151:maybeDeferred
  17. /home/debian/Escritorio/src/lib/python3.7/site-packages/daphne/ws_protocol.py:82:onConnect
  18. --- <exception caught here> ---
  19. /home/debian/Escritorio/src/lib/python3.7/site-packages/twisted/internet/defer.py:151:maybeDeferred
  20. /home/debian/Escritorio/src/lib/python3.7/site-packages/daphne/server.py:200:create_application
  21. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/staticfiles.py:41:__call__
  22. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/routing.py:58:__call__
  23. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/sessions.py:47:__call__
  24. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/sessions.py:145:__call__
  25. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/sessions.py:169:__init__
  26. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/middleware.py:31:__call__
  27. /home/debian/Escritorio/src/lib/python3.7/site-packages/channels/routing.py:154:__call__
  28. ]
  29. WebSocket DISCONNECT /ws/chat/lobby/ [127.0.0.1:46058]
  30. Not Found: /ws/chat/lobby/
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. # Este es el routing en proyecto
  38. # mysite/routing.py
  39. from channels.auth import AuthMiddlewareStack
  40. from channels.routing import ProtocolTypeRouter, URLRouter
  41. import chat.routing
  42.  
  43. application = ProtocolTypeRouter({
  44.     # (http->django views is added by default)
  45.     'websocket': AuthMiddlewareStack(
  46.         URLRouter(
  47.             chat.routing.websocket_urlpatterns
  48.         )
  49.     ),
  50. })
  51.  
  52.  
  53.  
  54. ## Esta es el routing en app:
  55. # chat/routing.py
  56. from django.urls import path
  57.  
  58. from . import consumers
  59.  
  60. websocket_urlpatterns = [
  61.     path('ws/chat/<str:room_name>/$', consumers.ChatConsumer),
  62. ]
  63.  
  64.  
  65. este es el consumers.py
  66. # chat/consumers.py
  67. from channels.generic.websocket import WebsocketConsumer
  68. import json
  69.  
  70. class ChatConsumer(WebsocketConsumer):
  71.     def connect(self):
  72.         self.accept()
  73.  
  74.     def disconnect(self, close_code):
  75.         pass
  76.  
  77.     def receive(self, text_data):
  78.         text_data_json = json.loads(text_data)
  79.         message = text_data_json['message']
  80.  
  81.         self.send(text_data=json.dumps({
  82.             'message': message
  83.         }))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement