django-ical is a simple library/framework for creating iCal feeds based on Django's syndication feed framework. It extends Django's built-in feed system to support iCalendar-specific properties and uses the `icalendar` library for generation. The current version is 1.9.2, and it is actively maintained by Jazzband.
pip install django-icalVerified import paths — ran on the pinned version, not inferred.
To create an iCal feed, define a model for your events, then create a subclass of `ICalFeed`. This class should implement methods like `items()`, `item_title()`, `item_description()`, `item_start_datetime()`, and critically, `item_guid()` for unique event identification. Finally, wire it into your `urls.py`.
Ensure `item_guid(self, item)` returns a truly unique string for each event, often by combining a unique database ID with a domain name, e.g., `f"event-{item.id}@yourdomain.com"`.Set the `file_name` attribute on your `ICalFeed` subclass (e.g., `file_name = 'events.ics'`). This can also be a method for dynamic filenames.
Do not rely on `item_link` for iCal feeds. The iCalendar standard uses `URL` for event links, which is not directly exposed as `item_link` but can be manually added as an extra property if needed via `item_extra_properties`.
Optimize your `items()` method using `select_related()` or `prefetch_related()` for related data. Avoid complex lookups in `item_*` methods if possible, or ensure data is pre-fetched.
Ensure you have run `pip install django-ical` and added `'django_ical'` to your `INSTALLED_APPS` list in `settings.py`.
Implement or review your `item_guid(self, item)` method to return a string that is universally unique for each distinct event, typically by embedding the event's primary key and your domain, e.g., `return f"event-{item.id}@yourdomain.com"`.Ensure that `HttpResponse` objects intended to serve `.ics` files have the correct `Content-Type` header (`'text/calendar'`) and that any manually generated iCalendar content uses `\r\n` for newlines as required by RFC 2445. `django-ical`'s `ICalFeed` handles this automatically.