Photo by Nicholas Safran on Unsplash
#3 - Install and Setup django
This would be the starting point to build Wobu
In my previous post, I shared the tech stack that will be used to build Wobu. In this post, let's take the first step of installing django.
I use pydanny's cookie cutter to install django, as it helps jumpstart development. Use it with caution though, as it comes with a lot of nuts and bolts, and sometimes it may become difficult to troubleshoot issues. Towards the end, I shall share a few points to be wary of.
Even before installing django, the zeroth step will be to install a virtual environment. The below commands are for a Windows machine, as I use that for local development.
pip install virtualenv
python --version
python<version> -m venv <virtual-environment-name>
On knowing the version of python in use, create a virtual environment accordingly and activate the same. If the python version does not work, just give without the version or simply python3
The next step is to use cookiecutter, and create a django project.
pip install "cookiecutter>=1.7.0"
cookiecutter https://github.com/cookiecutter/cookiecutter-django
Below is what I used to create my project
Hooray โจ Job done! Let's now look at a few points to keep in mind while using cookie cutter.
I'd suggest doing some reading upfront on the choices you will make before you run the above command. For example, if you are new to celery, and unsure whether you'll need it or not, do some quick reading and decide whether you may need it or not. The reason is, based on the choices we make, cookiecutter will add that many entries in the settings/base.py file. If something is unnecessary, then why add it in the first place, isn't it?
When you now try to run
python manage.py runserver
It will throw a lot of errors on missing packages and modules. You need to check one by one and install them in your virtual environment. Most of the packages will not be installed by default. Set aside half an hour to an hour to bring the server up without any hiccups.
Keep in mind that we will not have settings.py like how it is when we create a django project using
django-admin startproject <projectname>
Instead, it will be
This path will be used in configuration files and in code while we access values from base.py. So, do remember the path ๐ก
It creates the users app by default under the following folder path. If you are using cookiecutter for the first time, pay attention to this one.
AUTH_USER_MODEL, LOGIN_REDIRECT_URL, LOGIN_URL
will be set by default inbase.py
. If you name your User model as something else, say CustomUser then make sure to change it inbase.py
. Likewise, if you do not use django authentication for login, thenLOGIN_REDIRECT_URL
may not come into play at all. You need to handle it yourself.
These are a few points to keep a tab on when you get started. I shall share other properties as and when we get there.
Ooh hoo ๐, the wheels are in motion ๐ด