-
Notifications
You must be signed in to change notification settings - Fork 2
URL Patterns
Michael Beaton edited this page Nov 25, 2022
·
6 revisions
For django-wm
to work, you will need to include its URLs to your project's urlpatterns
. See endpoints for details.
# your_project/urls.py
urlpatterns = [
...
path("webmention/", include("mentions.urls")),
]
In order to associate incoming webmentions with your MentionableMixin models, your urlpatterns
will need to include some extra data. The following examples are equivalent to each other:
# your_app/urls.py
urlpatterns = [
mentions_path(
"article/<int:article_id>/",
ArticleView.as_view(),
model_class=Article,
model_filter_map={
"article_id": "id",
},
name="article",
),
]
Here, model_filter_map
is used to translate the captured kwarg article_id
to the model field lookup id
. This will generate a query of the form Article.objects.get(id=kwargs.get("article_id"))
.
This may be omitted if your view and model both use the same names: if your mapping would be {"id": "id"}
you don't have to include it.
# your_app/urls.py
urlpatterns = [
path(
"article/<int:article_id>/",
ArticleView.as_view(),
name="article",
kwargs={
"model_name": "sample_app.Article",
},
name="article",
),
]
# you_app/models.py
class Article(MentionableMixin, models.Model):
@classmethod
def resolve_from_url_kwargs(cls, article_id: int, **url_kwargs):
return Article.objects.get(id=article_id)