author Magesh

Django Developers Guild – Jan '23 summary

Magesh Ravi on Feb. 7, 2023

Django Developers Guild hosted its first online event on 28 January 2023 and discussed some important topics related to the Django framework. Here's a summary of the key takeaways from the event.

Why Django?

Django has become a popular framework for web development due to its speed of development, great community, and proven track record of performance and scalability.

Five common issues faced by Django beginners

Issue #1: Can't decide between venv, virtualenv and conda

VirtualEnvWrapper is much more beginner friendly when compared to other virtual environment tools, as it maintains all files in a separate location outside the project folder. Refer to this step-by-step guide to install virtualenvwrapper.

Issue #2: VS Code Intellisense doesn't work with virtual environments

The solution involves two steps – installing the python extension pack and configuring the python interpreter.

1️⃣ Python extension pack: Locate the extensions' icon in your VS Code sidebar and search for "Python".

search for python extension

Locate the extension pack by Microsoft containing Jupyter, isort and Pylance extensions, and install it.

locate microsoft's extension

Reload VS Code if required.

2️⃣ Configure python interpreter

Find the virtual environment's python path.

which python

Update VS Code's python interpreter.

select interpreter

Issue #3: Frequent indentation errors

Fix indentation errors by using the black formatter.

1️⃣ Install black.

pip install black

2️⃣ Configure Python formatter

Go to Settings, search for "python formatting provider" and select "Black".

formatting provider

Issue #4: Missing newlines and extra whitespaces

Configure VS Code to automatically add new lines at the end of files upon saving.

insert final newline

Configure VS Code to automatically remove whitespaces at the end of lines upon saving.

trailing whitespaces

Issue #5: Python's unit test or Pytest

Pytest is a better alternative to python's built-in unit testing library. It is compact (takes fewer lines to write), faster and provides a better way to organise test data through fixtures.

Issue #6: Data migrations vs Fixtures

Use data migrations when you need to add/remove rows across all environments – alpha, beta, staging and production. For example, pricing plans on a website (say GOLD, SILVER and PLATINUM).

Use fixtures (prefer YAML) when you must load consistent test data across testing environments (but not production). For example, test user accounts.

Other useful extensions

A few other extensions that Django developers might find useful.

If you found this article helpful, please share it with your friends. Our next edition of the Django Developers Guild meeting will happen on Saturday, 18 February 2023.