- make sure you have python installed.
- make sure you have django installed.
$ python -m django --version
if not install it.python -m pip install Django
django-admin startproject pubchat
python3 manage.py startapp chat
Add 'chat'
in the INSTALLED_APPS
in settings.py of pubchat/
create templates
in chat
add index.html
there, define view for index in views.py
in chat/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
in pubchat/urls.py
import include
from django.conf.urls
and add urlpattern for chat
app.
urlpatterns = [
path('/', include('chat.urls')),
...
]
for static content add
STATICFILES_DIRS = [
BASE_DIR / "static",
]
We will use different config for deployment
now $ python manage.py runserver
, you should see the contents on the template on root.
Verify you have Django Channels installed $ python -c 'import channels; print(channels.__version__)'
if not, install it
python -m pip install -U channels
Now add 'channels'
in the INSTALLED_APPS;
install pyjwt as well
pip install pyjwt
we have already used AuthMiddlewareStack in asgi.py
, which supports standard Django authentication, where the user details are stored in the session.
for our jwt token, let's now use our own middleware