-
Notifications
You must be signed in to change notification settings - Fork 2
Guide_Getting started
- Install
django-wm
- Add required settings
- Update project urlpatterns
- Add the mixin to your model(s)
- Update app urlpatterns
- Update migrations
- Test it!
PyPI: django-wm
pip install django-wm[celery]
Please follow these instructions to set up Celery, then come back here for the rest.
pip install django-wm
Please follow these instructions, then come back here for the rest.
For reference, source code for an example project is available here.
Add required settings:
In settings.py
:
- Set
DOMAIN_NAME
:
DOMAIN_NAME = "your.url.here" # e.g. "beatonma.org" ```
- Add
mentions
toINSTALLED_APPS
:
INSTALLED_APPS = [ ... "mentions", ] ```
- Add
mentions.middleware.WebmentionHeadMiddleware
toMIDDLEWARE
:
MIDDLEWARE = [ ... "mentions.middleware.WebmentionHeadMiddleware", ] ```
# yourproject/urls.py
urlpatterns = [
...
path("webmentions/", include("mentions.urls")),
]
Include MentionableMixin
in the model(s) you want to support webmention functionality.
Any models that include the mixin must implement the get_content_html
and get_absolute_url
methods:
# models.py
from mentions.models.mixins import MentionableMixin
class Article(MentionableMixin, models.Model):
content = models.TextField()
def get_content_html(self) -> str:
return self.content
def get_absolute_url(self) -> str:
return reverse("article", args=[self.id])
Add urlpatterns
metadata for any views that represent a MentionableMixin
model instance. The mentions_path
helper is the easiest way to do this - see here for details and further configuration options.
# your_app/urls.py
from mentions.helpers import mentions_path
urlpatterns = [
mentions_path(
"article/<int:article_id>/",
ArticleView.as_view(),
model_class=Article,
model_filter_map={
"article_id": "id",
},
name="article",
),
]
python manage.py makemigrations
python manage.py migrate
This page accepts Webmentions and lets you send one to yourself, so you can check that both incoming and outgoing Webmentions work on your server.