Python Django URL MAC地址匹配

Python Django URL MAC地址匹配,python,regex,django,Python,Regex,Django,我在Django中遇到了一个奇怪的模式匹配问题,正则表达式的一部分被插入到路径中 测试Mac:08:00:27:13:5A:B2 MAC地址模式:(?p[\dA-F]{2}(?:[-:][\dA-F]{2}){5}) 中的正则表达式测试 Url在Swagger中解析:GET/hostmanager/api/host/lookup/mac/{mac_address}{5})/ 结果请求:api/host/lookup/mac/08%3A00%3A27%3A13%3A5A%3AB2{5})/ 这将导

我在Django中遇到了一个奇怪的模式匹配问题,正则表达式的一部分被插入到路径中

测试Mac:
08:00:27:13:5A:B2

MAC地址模式:
(?p[\dA-F]{2}(?:[-:][\dA-F]{2}){5})

中的正则表达式测试

Url在Swagger中解析:
GET/hostmanager/api/host/lookup/mac/{mac_address}{5})/

结果请求:
api/host/lookup/mac/08%3A00%3A27%3A13%3A5A%3AB2{5})/

这将导致404错误。如果我删除
{5})
并重复请求,则请求成功

从Python
manage.py显示URL

/hostmanager/api/host/lookup/mac/<mac_address>{5})/ rest_framework.decorators.hostLookupMacAddress  host_lookup_mac_address 

尝试将命名捕获组以外的所有捕获组更改为非捕获组
MAC_-ADDRESS_-PATTERN=r'(?P(?[0-9A-Fa-f]{2}[:-]){5}(?[0-9A-Fa-f]{2}))
python manager.py show_-url的结果如下:GET/hostmanager/api/host/lookup/{MAC ADDRESS}{5}{var})/尝试将命名捕获组以外的所有捕获组更改为非捕获组
MAC_-ADDRESS_-PATTERN=r'(?P(?[0-9A-Fa-f]{2}[:-]){5}(?[0-9A-Fa-f]{2}))
你不重复同样的模式5次吗?这会导致python manager.py显示以下url:GET/hostmanager/api/host/lookup/{MAC ADDRESS}{5}{var})/
from django.conf.urls import patterns, url

from HostManager.Api.views import (
    hostLookupMacAddress,
)

MAC_ADDRESS_PATTERN = r'(?P<mac_address>([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}))'

urlpatterns = [
    url(r'^$', index, name="host_manager_api_home"),
    url(r'^host/lookup/mac/%s/'% MAC_ADDRESS_PATTERN , hostLookupMacAddress  , name='host_lookup_mac_address'),

]