Let’s Tango with Django

Anjelica A
4 min readMar 6, 2020

Django — you either love it or you hate it. There are a lot of things you can accomplish with Django, and one key feature I enjoy most about Django is how simple and easy it is to implement authentication and authorization in my websites. Django comes with a lot of built in features (just remember to import EVERYTHING). I like how organized Django is, as everything is name-spaced. I especially like making models in Django rather than making them in flask, since it’s short and sweet. One gripe I have with Django is the fact you have to remember to import everything (for example, if you want to use get_template() you have to import the command from django.template.loader. But otherwise, I really like using Django and have many ideas for Django projects for the near future.

Mochi Mochi

I’ve recently finished a project in Django called “Mochi-Mochi”. I’ve chosen this name because it is a play on the Japanese phrase: “もしもし” or (moshi-moshi) which means hello. The premise of Mochi-Mochi is to chat and meet new people.

Mochi-Mochi’s Header

Mochi-Mochi is a chat app, created using Django Channels. I followed a tutorial to make the chat function on my project: https://channels.readthedocs.io/en/latest/tutorial/index.html.

Channels Tutorial

I highly recommend this tutorial; it is very easy to follow, and beginner-friendly. The tutorial teaches you step by step on how to create an asynchronous chat server, meaning that if I were to open my chatroom in another window, the chat log will still be there. One should keep in mind the tutorial requires you to install a couple of add-ons. Add ons such as channels-redis, daphne, docker, and selenium and chromedriver for testing.

Here’s how the tutorial configures the Channel Layers

The tutorial does a very good job of going into depth about channel layers. Channel layers provide two abstractions, like the channel itself which is like a mailbox for messages to be sent into. If you have the name of a channel (in this case, the name of the chatroom), you can access the messages in it. Then, there’s the group which is, as its name suggests, a group of related channels. If you have the name of the group, you can add or remove a channel to the group by name and send a message to all channels in the group.

How Chatting Works

Here’s a rundown on how users can use the chat app:

Users will be asked for the name of a chatroom. If it does not already exist, it will create a new one.
Type your message and press send…
Voila!

I made some edits to the tutorial so the messages will persist if you close the window or refresh the page (by saving it to a database), as well as a clear button so you can start off on a blank slate.

FriendCards

One feature I’ve implemented is FriendCards. As of the current build, you can only create FriendCards and check the ones you’ve made. In the future, I’d like to make some tweaks to FriendCards. For example, I’ll limit it so users can only have one FriendCard each, and when you meet in a chatroom, you will automatically obtain the other user’s card. The more people you meet, the more cards you’ll accumulate.

Conclusion

There are a lot of things I’d like to add to Mochi-Mochi in the future. I want to make Mochi-Mochi a great place to chat and meet people with the same interests. I will continue my studies and hope to one day make my vision for Mochi Mochi a reality.

--

--