A Django app to conduct Web-based socket-test-package.
Project description
Chat is a Django app to conduct Web-based Chat. For each question, visitors can choose between a fixed number of answers.
Detailed documentation is in the “docs” directory.
Quick start
Add “chat” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'chat', ] USE_DEFAULT_TEMPLATES=False
Include the chat URLconf in your project urls.py like this:
path('chat/', include('chat.urls')),
Run python manage.py migrate to create the chat models.
Add to settings.py this:
ASGI_APPLICATION = 'your_project_name.asgi.application' CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [('127.0.0.1', 6379)], }, }, } WEBSOCKETPATH='127.0.0.1:8000'
Create routing.py file in project folder:
from django.urls import path from channels.routing import URLRouter from chat.consumers import ChatConsumer ws_application = [ path("ws/chat/",ChatConsumer.as_asgi()) ]
Write in asgi.py file in project folder:
import os from channels.routing import URLRouter,ProtocolTypeRouter from channels.security.websocket import AllowedHostsOriginValidator from channels.auth import AuthMiddlewareStack from django.core.asgi import get_asgi_application from .routing import ws_application application = ProtocolTypeRouter({ 'websocket': AllowedHostsOriginValidator( AuthMiddlewareStack( URLRouter( ws_application ) ) ) })
Start the development server and visit http://127.0.0.1:8000/admin/ to create a chat (you’ll need the Admin app enabled).
Visit http://127.0.0.1:8000/chat/ to participate in the chat.
If you want to use your template:
write views.py from chat.use_customs import CustomTemplate CustomTemplate.chat_template_name='mychat.html' CustomTemplate.login_template_name='mylogin.html' CustomTemplate.signup_template_name='mysignup.html'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.