Django Girls Tutorial

Installation

To install software on your machine, follow the instructions below:

Brief intro to the command line

Many of the steps below reference the “console”, “terminal”, “command window”, or “command line” — these all mean the same thing: a window on your computer where you can enter commands. When you get to the main tutorial, you’ll learn more about the command line. For now, the main thing you need to know is how to open a command window and what it looks like:

It’s probably under Applications → Accessories → Terminal, or Applications → System → Terminal, but that may depend on your system. If it’s not there, you can try to Google it. :)

The Command-line Prompt

Now you know how to open a command line, we just need to understand what the “prompt” is.

If you’re on Linux, you probably see a $, like this:

command-line

$

Each command will be prepended by a $ and one space, but you should not type it. Your computer will do it for you. :)

Just a small note: in your case there may be something like ola@Olas-PC:~ $ before the prompt sign, and this is 100% OK.

The part up to and including the $ is called the command line prompt, or prompt for short. It prompts you to input something there.

In the tutorial, when we want you to type in a command, we will include the $, and occasionally more to the left. Ignore the left part and only type in the command, which starts after the prompt.

Install Python

For readers at home: this chapter is covered in the Installing Python & Code Editor video.

This section is based on a tutorial by Geek Girls Carrots (https://github.com/ggcarrots/django-carrots)

Django is written in Python. We need Python to do anything in Django. Let’s start by installing it! We want you to install the latest version of Python 3, so if you have any earlier version, you will need to upgrade it. If you already have version 3.10 or higher you should be fine.

Please install normal Python as follows, even when you have Anaconda installed on your computer.

It is very likely that you already have Python installed out of the box. To check if you have it installed (and which version it is), open a console and type the following command:

command-line

$ python3 --version
Python 3.12.3

If you have a different version of Python installed, at least 3.10 (e.g. 3.10.13), then you don’t have to upgrade. If you don’t have Python installed, or if you want a different version, first check which Linux distribution you are using with the following command:

command-line

$ grep '^NAME=' /etc/os-release

Afterwards, depending on the result, follow one of the following installation guides below this section.

Install Python: Debian or Ubuntu

Type this command into your console:

command-line

$ sudo apt install python3
Install Python: Fedora

Use this command in your console:

command-line

$ sudo dnf install python3

If you’re on older Fedora versions you might get an error that the command dnf is not found. In that case, you need to use yum instead.

Install Python: openSUSE

Use this command in your console:

command-line

$ sudo zypper install python3

Verify the installation was successful by opening a command prompt and running the python3 command:

command-line

$ python3 --version
Python 3.12.3

The version shown may be different from 3.12.3 — it should match the version you installed.


If you have any doubts, or if something went wrong and you have no idea what to do next, please ask your coach! Sometimes things don’t go smoothly and it’s better to ask for help from someone with more experience.

Install a code editor

There are a lot of different editors and it largely boils down to personal preference. Most Python programmers use complex but extremely powerful IDEs (Integrated Development Environments), such as PyCharm. As a beginner, however, that’s probably less suitable; our recommendations are equally powerful, but a lot simpler.

Our suggestions are below, but feel free to ask your coach what their preferences are – it’ll be easier to get help from them.

Visual Studio Code

Visual Studio Code is a source code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.

Download it here

Gedit

Gedit is an open-source, free editor, available for all operating systems.

Download it here

Sublime Text

Sublime Text is a very popular editor with a free evaluation period and it’s available for all operating systems.

Download it here

Why are we installing a code editor?

You might be wondering why we are installing this special code editor software, rather than using something like Word or Notepad.

The first reason is that code needs to be plain text, and the problem with programs like Word and Textedit is that they don’t actually produce plain text, they produce rich text (with fonts and formatting), using custom formats like RTF (Rich Text Format).

The second reason is that code editors are specialized for editing code, so they can provide helpful features like highlighting code with color according to its meaning, or automatically closing quotes for you.

We’ll see all this in action later. Soon, you’ll come to think of your trusty old code editor as one of your favorite tools. :)

Set up virtualenv and install Django

Part of this section is based on tutorials by Geek Girls Carrots (https://github.com/ggcarrots/django-carrots).

Part of this section is based on the django-marcador tutorial licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. The django-marcador tutorial is copyrighted by Markus Zapke-GrĂĽndemann et al.

Virtual environment

Before we install Django we will get you to install an extremely useful tool to help keep your coding environment tidy on your computer. It’s possible to skip this step, but it’s highly recommended to follow it. Starting with the best possible setup will save you a lot of trouble in the future!

So, let’s create a virtual environment (also called a virtualenv). Virtualenv will isolate your Python/Django setup on a per-project basis. This means that any changes you make to one website won’t affect any others you’re also developing. Neat, right?

All you need to do is find a directory in which you want to create the virtualenv; your home directory, for example. On Windows, it might look like C:\Users\Name\ (where Name is the name of your login).

For this tutorial we will be using a new directory djangogirls from your home directory:

command-line

$ mkdir djangogirls
$ cd djangogirls

We will make a virtualenv called myvenv. The general command will be in the format:

command-line

$ python3 -m venv myvenv

We can create a virtualenv on Linux by running python3 -m venv myvenv. It will look like this:

command-line

$ python3 -m venv myvenv

myvenv is the name of your virtualenv. You can use any other name, but stick to lowercase and use no spaces. It is also a good idea to keep the name short as you’ll be referencing it a lot!

NOTE: On some versions of Debian/Ubuntu you may receive the following error:

command-line

The virtual environment was not created successfully because ensurepip is not available.  On Debian/Ubuntu 
systems, you need to install the python3-venv package using the following command.
   apt install python3-venv
You may need to use sudo with that command.  After installing the python3-venv package, recreate your 
virtual environment.

In this case, follow the instructions above and install the python3-venv package: command-line

$ sudo apt install python3-venv

NOTE: On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:

command-line

>Error: Command '['/home/eddie/Slask/tmp/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', 
'--default-pip']' returned non-zero exit status 1

To get around this, use the virtualenv command instead.

command-line

$ sudo apt install python-virtualenv
$ virtualenv --python=python3.12 myvenv

NOTE: If you get an error like

command-line

E: Unable to locate package python3-venv

then instead run:

command-line

sudo apt install python3.12-venv

Install Git

Git is a “version control system” used by a lot of programmers. This software can track changes to files over time so that you can recall specific versions later. A bit like the “track changes” feature in word processor programs (e.g., Microsoft Word or LibreOffice Writer), but much more powerful.

Installing Git

Installing Git: Debian or Ubuntu

command-line

$ sudo apt install git
Installing Git: Fedora

command-line

$ sudo dnf install git
Installing Git: openSUSE

command-line

$ sudo zypper install git

Create a GitHub account

Go to GitHub.com and sign up for a new, free user account. Be sure to remember your password (add it to your password manager, if you use one).

Create a PythonAnywhere account

PythonAnywhere is a service for running Python code on servers “in the cloud”. We’ll use it for hosting our site, live and on the Internet.

We will be hosting the blog we’re building on PythonAnywhere. Sign up for a “Beginner” account on PythonAnywhere (the free tier is fine, you don’t need a credit card).

The PythonAnywhere signup page showing button to create a free 'Beginner' account

Note When choosing your username here, bear in mind that your blog’s URL will take the form yourusername.pythonanywhere.com, so choose either your own nickname or a name for what your blog is all about. Also, be sure to remember your password (add it to your password manager, if you use one).

Creating a PythonAnywhere API token

This is something you only need to do once. When you’ve signed up for PythonAnywhere, you’ll be taken to your dashboard. Find the link near the top right to your “Account” page:

Account link on the top right on the page

then select the tab named “API token”, and hit the button that says “Create new API token”.

The API token tab on the Account page

Start reading

Congratulations, you are all set up and ready to go! If you still have some time before the workshop, it would be useful to start reading a few of the beginning chapters:

Enjoy the workshop!

When you begin the workshop, you’ll be able to go straight to Your first Django project! because you already covered the material in the earlier chapters.