This is an example project demonstrating how to take advantage of HTMX requests to do partial rendering for list view in Django.
The complete blog post can be found here.
You can find here:
- Dynamic Search: search functionality without reloading the page.
- "Load More": button to add additional results dynamically to the page.
Clone the project:
# SSH
git clone [email protected]:katiayn/django-imdb.git
# HTTPS
git clone https://github.com/katiayn/django-imdb.git
Create and activate the virtual environment:
# Unix/macOS
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $
# Windows
$ python -m venv .venv
$ .venv\Scripts\activate
(.venv) $
Install the required packages:
python3 -m pip install -r requirements.txt
We use OMDB (Open Movie Database) to fetch a few sample titles. You can get an API Key here.
The environment variables are stored in the .env
file.
Duplicate .env.dist
file and rename it to .env
. Update the environment variables:
DEBUG=True
SECRET_KEY=<your-secret-key>
DATABASE_URL=postgres://postgres:postgres@localhost:5432/imdb
DJANGO_IMDB_OMDB_API_KEY=<your-omdb-api-key>
REDIS_URL=redis://localhost:6379/
The default
DATABASE_URL
ispostgres://postgres:postgres@localhost:5432/imdb
(checkdjango_imdb/settings.py
).
After generating the OMDB API Key, you can run the command to create the initial data:
python3 manage.py add_imdb_titles
You can add more titles running the same command:
python3 manage.py add_imdb_titles --imdb_ids <imdb_id> <imdb_id>...
For example:
python3 manage.py add_imdb_titles --imdb_ids tt2306299 tt0773262 tt0108052 tt0102926
imdb_id
is the id from IMDb url: https://www.imdb.com/title/<imdb_id> (e.g. https://www.imdb.com/title/tt1853728/)