2

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.