Django URL MAC地址匹配

时间:2016-03-30 12:14:00

标签: python regex django

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

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

MAC_ADDRESS_PATTERN:(?P<mac_address>[\dA-F]{2}(?:[-:][\dA-F]{2}){5})

Pythex

中的正则表达式测试

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 show_urls

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

urls.py

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'),

]

0 个答案:

没有答案