【问题标题】:In Django, pass parameters in href when a href uses the urlpattern not the url tag在 Django 中,当 href 使用 urlpattern 而不是 url 标签时,在 href 中传递参数
【发布时间】:2018-12-16 12:43:43
【问题描述】:

我试图在 urlpattern 而不是 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/ 中发送一个参数,我该如何设置?

【问题讨论】:

    标签: django url parameters href


    【解决方案1】:

    您可以使用reversereverse-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
        }
    

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 1970-01-01
      • 2018-05-21
      • 2020-12-28
      • 2016-10-24
      • 2017-08-11
      • 1970-01-01
      • 2016-01-25
      • 2017-02-02
      相关资源
      最近更新 更多