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.11 -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:
# server/requirements.txt
Django==4.1.7
django-filter==22.1
djangorestframework==3.14.0
elasticsearch-dsl==7.4.0
psycopg2-binary==2.9.5
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