Kamal Mustafa
Kamal's Blog

Follow

Kamal's Blog

Follow

Toolkit vs libraries

Kamal Mustafa's photo
Kamal Mustafa
·Dec 15, 2022·

2 min read

I want to test something with Django, when working on new blog post about project structure. So I went to my terminal and create a new directory to hold the new django project.

The command to start a new django project is django-admin startproject. But I stumbled there because I don't have the command django-admin. This is one thing that always confuses the newbie and make them stuck.

I paused a bit to reflect on how an inexperienced Django developer would think in this situation. There are many ways to go from here and it might feel daunting to some people. This is because we're facing different levels of concepts here but to inexperienced developers, it is just one bag of confusing things.

Django here exists as both a toolkit (in form of the django-admin command) and libraries (when you do import django ... in your app).

One quick way is to create a new virtual environment in the current directory I'm working on.

python -mvenv venv

Then I can install django inside that newly created venv:-

venv/bin/pip install django
venv/bin/django-admin startproject

I will also continue to use that venv to run my django project:-

cd myproject
../venv/bin/python manage.py runserver

So both the tooling (django-admin) and the libraries (django) in the same virtualenv. There's also another way to go, by treating django-admin as toolkit and install it "globally" within my $HOME environment. For this purpose I usually use pipx to install all the common tools I'm using for development.

pipx install django
django-admin startproject myproject
python -mvenv venv
venv/bin/pip install django
cd myproject
../venv/bin/python manage.py runserver

Above, I'm treating django-admin as toolkit and installing it to global $HOME so it is always available whenever I need it. But for myproject I'm installing a separate django in venv specific for that project.

So what else that I'm treating as toolkit?

  • Black

  • Flake8

  • Pre-commit

  • ...

For futher reading, head ups to this stackoverflow question.

 
Share this