Machine Learning with Django logo ML with Django

What you will learn in this chapter:

Setup git repository

To set up a git repository I use GitHub (it is free for public and private projects). If you have an account there please go to and set the repository, like in the image below.

Setup a new project in github
Setup a new project in github

The full code of this tutorial is available at:

Then please go to your terminal and set the repository:

git clone
cd my_ml_service
ls -l

In my case, I had two files in the repository, LICENSE and


Let’s set up and activate the environment for development (I’m using Ubuntu 16.04). I will use virtualenv:

virtualenv venv --python=python3.6
source venv/bin/activate

You will need to activate the environment every time you are starting work on your project in the new terminal.

To install needed packages I will use pip3:

pip3 install django==2.2.4

The Django is installed in version 2.2.4.

Start Django project

I will set up the Django project in the backend directory. The Django project name is set to server.

mkdir backend
cd backend
django-admin startproject server

You can run your initiated server with the following command:

cd server
python runserver

When you enter in your favorite web browser you should see default Django welcome site.

Django default welcome site
Django default welcome site

Congratulations!!! you have successfully set up the environment.

Add source files to the repository

Before we go to the next chapter, let’s commit new files.

# please execute it in your main project directory
git add backend/
git commit -am "setup django project"
git push

The following files should be added to your project:

new file:   backend/server/
new file:   backend/server/server/
new file:   backend/server/server/
new file:   backend/server/server/
new file:   backend/server/server/

In your directory, there are other files which are not added to the repository because there are excluded in .gitignore file.

Next step: Train ML models