Django Rest API Url Pattern to handle . (dot) symbol

Viewed 204

Creating Django REST API, Need suggestions to handle the .(dot char) in the 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

Below URL pattern does not work when name = ABC.XYZ 

url(r'^tests/(?P<string>[\w\-]+)/$', views.tests.as_view(), name='api_tests_name')
1 Answers

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.

Related