Create Project

Part 1, Chapter 3


Before you begin this tutorial, you'll need a recent version of Python 3 on your machine. If you are using Mac OS and don't have Python 3, I recommend installing it using Homebrew.

Create a directory to hold the project:

$ mkdir perusable && cd perusable

Next, make a "server" directory inside the "perusable" directory:

$ mkdir server && cd server

Create and activate a virtual environment:

$ python3.9 -m venv env
$ source env/bin/activate
(env)$

Feel free to swap out venv and Pip for Poetry or Pipenv. For more, review Modern Python Environments.

Create a file called server/requirements.txt:

Django==3.1.7
django-filter==2.4.0
djangorestframework==3.12.2
elasticsearch-dsl==7.3.0
psycopg2-binary==2.8.6

Here, we defined the Python library requirements for our app, which include Django, Django Filter, Django REST Framework, Elasticsearch DSL, and Psycopg2.

Use pip to install the dependencies and then create a new Django project and app:

(env)$ pip install -r requirements.txt
(env)$ django-admin startproject perusable .
(env)$ python manage.py startapp catalog

Your project structure should now look like this:

└── server
    ├── catalog
    │   ├── __init__.py
    │   ├── admin.py
    │   ├── apps.py
    │   ├── migrations
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── tests.py
    │   └── views.py
    ├── manage.py
    ├── perusable
    │   ├── __init__.py
    │   ├── asgi.py
    │   ├── settings.py
    │   ├── urls.py
    │   └── wsgi.py
    └── requirements.txt



Mark as Completed