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 https://github.com/new 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: https://github.com/pplonski/my_ml_service.

Then please go to your terminal and set the repository:

git clone https://github.com/pplonski/my_ml_service.git
cd my_ml_service
ls -l

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

Installation

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 manage.py runserver

When you enter 127.0.0.1:8000 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/manage.py
new file:   backend/server/server/__init__.py
new file:   backend/server/server/settings.py
new file:   backend/server/server/urls.py
new file:   backend/server/server/wsgi.py

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