Skip to main content

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

  1. Add “chat” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'chat',
    ]
    
    USE_DEFAULT_TEMPLATES=False
  2. Include the chat URLconf in your project urls.py like this:

    path('chat/', include('chat.urls')),
  3. Run python manage.py migrate to create the chat models.

  4. 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'
  5. 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())
    ]
  6. 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
            )
            )
        )
    })
  7. Start the development server and visit http://127.0.0.1:8000/admin/ to create a chat (you’ll need the Admin app enabled).

  8. Visit http://127.0.0.1:8000/chat/ to participate in the chat.

  9. 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

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chat-app-package-0.1.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file chat-app-package-0.1.tar.gz.

File metadata

  • Download URL: chat-app-package-0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for chat-app-package-0.1.tar.gz
Algorithm Hash digest
SHA256 967dadcdf58f0fb7ddf2da8b497bbebaba7fd84957e4d274e4b57b291fce2d0a
MD5 4f0fde70c6cf9e8734376f1a07e94008
BLAKE2b-256 aa2eaa7b069b3b064a518c2f6e7273df2213f94f94fcb02e88cbe1051424d032

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page