【问题标题】:django url how to specify 2 or more stringsdjango url如何指定2个或更多字符串
【发布时间】:2012-10-20 20:49:08
【问题描述】:

我要匹配以下网址

 url(r'^home/Physician|Vendor/$, 'ViewerLog', name="monitor_viewerLog"),

如何匹配医师或供应商?这是正确的方法吗?

【问题讨论】:

    标签: python regex django django-urls


    【解决方案1】:

    要匹配医师或供应商,请使用括号。

    url(r'^home/(Physician|Vendor)/$, 'ViewerLog', name="monitor_viewerLog"),
    

    这将使用匹配的值作为参数调用您的视图。如果您不想捕获匹配的值,请使用(?:...)

    url(r'^home/(?:Physician|Vendor)/$, 'ViewerLog', name="monitor_viewerLog"),
    

    【讨论】:

      【解决方案2】:

      如果你想捕获匹配的值,你可以命名你返回的参数:

      url(r'^home/(?P<guy>Physician|Vendor)/$', 'ViewerLog', name="monitor_viewerLog"),
      

      【讨论】:

        猜你喜欢
        • 2021-09-15
        • 1970-01-01
        • 2018-03-13
        • 1970-01-01
        • 2020-08-25
        • 1970-01-01
        • 1970-01-01
        • 2017-07-26
        • 2011-08-04
        相关资源
        最近更新 更多