Create the detail template. By convention it is named
``/_detail.html``, and the content object is available
under its model name (``articlecontent``) in both the app-hook view and the
frontend editor — so create
``my_content/templates/my_content/articlecontent_detail.html``:
.. code-block:: django
{% extends "base.html" %}
{% load cms_tags %}
{% block content %}
{% cms_edit_on %}
{{ articlecontent.title }}
Published on {{ articlecontent.id }}
{{ articlecontent.body|safe }}
{% cms_edit_off %}
{% endblock %}
See :doc:`../how-to/apphooks` for the full template contract (why
``articlecontent`` rather than ``object``).
Step 3: Enable App Hook
-----------------------
To enable URL routing for articles, add ``apphook = True`` to ``ArticleContent.CMSConfig``:
Update ``my_content/models.py``:
.. code-block:: python
class ArticleContent(AbstractCustomContent):
"""The editable article content."""
article = models.ForeignKey(Article, on_delete=models.CASCADE)
title = models.CharField(max_length=200)
slug = models.SlugField()
body = models.TextField()
class CMSConfig:
# Make editable in the frontend and versionable
enable_frontend_editing = True
enable_versioning = True
# Enable URL routing via app hook
apphook = True
def __str__(self):
return self.title
That's all you need! The generic detail view will automatically handle URL routing.
Step 4: Add the App Hook to a CMS Page
---------------------------------------
In the Django CMS admin:
1. Create a new Django CMS page (or edit an existing one)
2. Go to the **Advanced** tab
3. Under **Application**, select your app hook ("My Content")
4. Save the page
The generic detail view automatically handles displaying articles by slug.
Done!
-----
Your article model now has:
✅ CMS plugins for teaser and list display
✅ An app hook for frontend URLs
✅ Proper templates
✅ Frontend display of articles
Next Steps:
- :doc:`model_with_m2m` - Add authors to articles using M2M relations
- :doc:`../how-to/m2m_relations` - Learn more about generic M2M relations
- :doc:`../explanation/architecture` - Understand the grouper/content pattern