Skip to content

Commit f5f3fc8

Browse files
committed
Simplify url patterns
Favor `django.urls.path` over `re_path` where possible.
1 parent 4e3e76f commit f5f3fc8

File tree

3 files changed

+41
-39
lines changed

3 files changed

+41
-39
lines changed

anymail/urls.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.urls import re_path
1+
from django.urls import path, re_path
22

33
from .webhooks.amazon_ses import (
44
AmazonSESInboundWebhookView,
@@ -18,89 +18,91 @@
1818

1919
app_name = "anymail"
2020
urlpatterns = [
21-
re_path(
22-
r"^amazon_ses/inbound/$",
21+
path(
22+
"amazon_ses/inbound/",
2323
AmazonSESInboundWebhookView.as_view(),
2424
name="amazon_ses_inbound_webhook",
2525
),
2626
re_path(
27+
# Mailgun delivers inbound messages differently based on whether
28+
# the webhook url contains "mime" (anywhere). You can use either
29+
# ".../mailgun/inbound/" or ".../mailgun/inbound_mime/" depending
30+
# on the behavior you want.
2731
r"^mailgun/inbound(_mime)?/$",
2832
MailgunInboundWebhookView.as_view(),
2933
name="mailgun_inbound_webhook",
3034
),
31-
re_path(
32-
r"^mailjet/inbound/$",
35+
path(
36+
"mailjet/inbound/",
3337
MailjetInboundWebhookView.as_view(),
3438
name="mailjet_inbound_webhook",
3539
),
36-
re_path(
37-
r"^postal/inbound/$",
40+
path(
41+
"postal/inbound/",
3842
PostalInboundWebhookView.as_view(),
3943
name="postal_inbound_webhook",
4044
),
41-
re_path(
42-
r"^postmark/inbound/$",
45+
path(
46+
"postmark/inbound/",
4347
PostmarkInboundWebhookView.as_view(),
4448
name="postmark_inbound_webhook",
4549
),
46-
re_path(
47-
r"^sendgrid/inbound/$",
50+
path(
51+
"sendgrid/inbound/",
4852
SendGridInboundWebhookView.as_view(),
4953
name="sendgrid_inbound_webhook",
5054
),
51-
re_path(
52-
r"^sparkpost/inbound/$",
55+
path(
56+
"sparkpost/inbound/",
5357
SparkPostInboundWebhookView.as_view(),
5458
name="sparkpost_inbound_webhook",
5559
),
56-
re_path(
57-
r"^amazon_ses/tracking/$",
60+
path(
61+
"amazon_ses/tracking/",
5862
AmazonSESTrackingWebhookView.as_view(),
5963
name="amazon_ses_tracking_webhook",
6064
),
61-
re_path(
62-
r"^mailgun/tracking/$",
65+
path(
66+
"mailgun/tracking/",
6367
MailgunTrackingWebhookView.as_view(),
6468
name="mailgun_tracking_webhook",
6569
),
66-
re_path(
67-
r"^mailjet/tracking/$",
70+
path(
71+
"mailjet/tracking/",
6872
MailjetTrackingWebhookView.as_view(),
6973
name="mailjet_tracking_webhook",
7074
),
71-
re_path(
72-
r"^postal/tracking/$",
75+
path(
76+
"postal/tracking/",
7377
PostalTrackingWebhookView.as_view(),
7478
name="postal_tracking_webhook",
7579
),
76-
re_path(
77-
r"^postmark/tracking/$",
80+
path(
81+
"postmark/tracking/",
7882
PostmarkTrackingWebhookView.as_view(),
7983
name="postmark_tracking_webhook",
8084
),
81-
re_path(
82-
r"^sendgrid/tracking/$",
85+
path(
86+
"sendgrid/tracking/",
8387
SendGridTrackingWebhookView.as_view(),
8488
name="sendgrid_tracking_webhook",
8589
),
86-
re_path(
87-
r"^sendinblue/tracking/$",
90+
path(
91+
"sendinblue/tracking/",
8892
SendinBlueTrackingWebhookView.as_view(),
8993
name="sendinblue_tracking_webhook",
9094
),
91-
re_path(
92-
r"^sparkpost/tracking/$",
95+
path(
96+
"sparkpost/tracking/",
9397
SparkPostTrackingWebhookView.as_view(),
9498
name="sparkpost_tracking_webhook",
9599
),
96100
# Anymail uses a combined Mandrill webhook endpoint,
97101
# to simplify Mandrill's key-validation scheme:
98-
re_path(
99-
r"^mandrill/$", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"
100-
),
102+
path("mandrill/", MandrillCombinedWebhookView.as_view(), name="mandrill_webhook"),
101103
# This url is maintained for backwards compatibility with earlier Anymail releases:
102-
re_path(
103-
r"^mandrill/tracking/$",
104+
path(
105+
"mandrill/tracking/",
104106
MandrillCombinedWebhookView.as_view(),
105107
name="mandrill_tracking_webhook",
106108
),

docs/installation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ If you want to use Anymail's inbound or tracking webhooks:
142142

143143
.. code-block:: python
144144
145-
from django.urls import include, re_path
145+
from django.urls import include, path
146146
147147
urlpatterns = [
148148
...
149-
re_path(r'^anymail/', include('anymail.urls')),
149+
path("anymail/", include("anymail.urls")),
150150
]
151151
152152
(You can change the "anymail" prefix in the first parameter to
153-
:func:`~django.urls.re_path` if you'd like the webhooks to be served
153+
:func:`~django.urls.path` if you'd like the webhooks to be served
154154
at some other URL. Just match whatever you use in the webhook URL you give
155155
your ESP in the next step.)
156156

tests/test_settings/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from django.urls import include, re_path
1+
from django.urls import include, path
22

33
urlpatterns = [
4-
re_path(r"^anymail/", include("anymail.urls")),
4+
path("anymail/", include("anymail.urls")),
55
]

0 commit comments

Comments
 (0)