How to Create a Django Application Using Poetry
Modern Python development encourages using tools that handle dependency management and environment isolation effectively. Poetry is one of the most popular solutions today. In this guide, you’ll learn how to create a Django application from scratch using Poetry.
What Is Poetry?
Poetry is a modern dependency and packaging manager for Python. It simplifies managing virtual environments, installing dependencies, and building your Python projects.
Prerequisites
- Python 3.7 or higher
- Poetry installed
- Basic command line knowledge
Step 1: Install Poetry
If you haven’t installed Poetry yet, run:
curl -sSL https://install.python-poetry.org | python3 -
After installation, restart your terminal and check:
poetry --version
Step 2: Create a New Poetry Project
Create your project folder:
poetry new mysite
cd mysite
This creates a new directory mysite/ with the following structure:
mysite/
├── mysite/
│ └── __init__.py
├── tests/
│ └── __init__.py
├── pyproject.toml
Step 3: Add Django as a Dependency
Tell Poetry to install Django:
poetry add django
Poetry updates your pyproject.toml file and installs Django inside a virtual environment.
Step 4: Activate the Virtual Environment
To activate Poetry’s virtual environment, run:
poetry shell
You are now inside an isolated environment with Django available.
Step 5: Create Your Django Project
From inside the Poetry shell, create a Django project:
django-admin startproject config .
The
.tells Django to use the current directory rather than creating a subfolder.
You now have:
mysite/
├── config/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── asgi.py
│ └── wsgi.py
├── manage.py
├── pyproject.toml
Step 6: Run the Development Server
Run the initial migration and start the server:
python manage.py migrate
python manage.py runserver
Now visit http://127.0.0.1:8000 in your browser—you’re up and running!
Step 7 (Optional): Add Development Tools
Want code formatting and linting? Add dev dependencies like so:
poetry add --group dev black flake8 isort
These tools help enforce clean code standards.
Summary of Commands
curl -sSL https://install.python-poetry.org | python3 -
poetry new mysite
cd mysite
poetry add django
poetry shell
django-admin startproject config .
python manage.py migrate
python manage.py runserver
Final Tips
- Use
poetry installto install all dependencies frompyproject.tomlon a new machine. - Use
poetry add package_nameto add new dependencies. - Manage Python version with
poetry env use python3.xif needed.
By combining the power of Django with the modern tooling of Poetry, you get a cleaner, more maintainable development experience. This setup is ideal for solo projects, startups, and even enterprise applications.