在 Django 中,当 href 使用 url 模式而不是 url 标记时,在 href 中传递参数

In Django, pass parameters in href when a href uses the urlpattern not the url tag

我试图在 url 模式而不是 url 标记中传递参数。

在urls.py、

   re_path(r'^send/(?P<uidb64>[0-9A-Za-z_\-]+)/$', views.send_email, name='send_email'),

在views.py、

   error_messages = { ...
        'inactive': _('<a href="/send/">Please get a new email</a>.'),
    }

我必须在 /send/ 中发送一个参数,我该如何设置?

你可以这样尝试 reverse or reverse-lazy:

 error_messages = { ...
        'inactive': _('<a href="{}">Please get a new email</a>.'.format(reverse('send_email', args=[some_uuid]))),  # where some_uuid will have uuid for the url
    }