Project Setup
Learn about Project Setup
Creating a Virtual Environment
Open your terminal and create a new project directory. Then create a Python virtual environment inside it to isolate your project dependencies:
mkdir django-htmx-contacts
cd django-htmx-contacts
python -m venv venv
Activating the Virtual Environment
Activate the virtual environment. On Mac and Linux use source venv/bin/activate. On Windows use venv\Scripts\activate. You should see (venv) appear at the beginning of your terminal prompt, confirming the environment is active.
Installing Django and HTMX
With the virtual environment active, install Django and the django-htmx helper package:
pip install django django-htmx
Creating the Django Project
Use the django-admin command to scaffold a new project. The dot at the end tells Django to create the project in the current directory:
django-admin startproject config .
Creating the Contacts App
Django projects are organized into "apps" — modular components that handle specific features. Create an app for our contacts functionality:
python manage.py startapp contacts
Then register the new app by adding "contacts" and "django_htmx" to the INSTALLED_APPS list in config/settings.py. Also add the HtmxMiddleware to the MIDDLEWARE list.
Running the Server
Start the development server to verify everything is working:
python manage.py runserver
Open http://127.0.0.1:8000 in your browser. You should see the Django welcome page with the rocket ship animation. Your project is ready to go.