[英]Django Rest API Url Pattern to handle . (dot) symbol
Creating Django REST API, Need suggestions to handle the .创建 Django REST API,需要建议来处理. (dot char) in the urlpatterns. (点字符)在 urlpatterns 中。 Below is the example detail:以下是示例详细信息:
I have a Model (test) with name as one of the fields and name value is of format ABC.XYZ我有一个 Model (测试),名称作为字段之一,名称值的格式为 ABC.XYZ
Below URL pattern does not work when name = ABC.XYZ
url(r'^tests/(?P<string>[\w\-]+)/$', views.tests.as_view(), name='api_tests_name')
You can add the dot to the character group in the regex:您可以将点添加到正则表达式中的字符组:
url(r'^tests/(?P<string>[\w\-.]+)/$', views.tests.as_view(), name='api_tests_name')
So now you make a request with tests/foo.bar/
as path for example.因此,现在您使用tests/foo.bar/
作为路径发出请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.