I have registered routers for user
model, which has viewset that has lookup_url as username
.
The username james adams
is accepted by the router, but getting below error for james i. adams
django.urls.exceptions.NoReverseMatch: Reverse for 'user-detail' with keyword arguments '{'username': 'james i. adam', 'version': 'v1'}' not found. 4 pattern(s) tried: ['(?P<version>(v4))/users/(?P<username>[^/.] )/?\\.(?P<format>[a-z0-9] )/?$', '(?P<version>(v4))/users/(?P<username>[^/.] )/?$', '(?P<version>(v1))/users/(?P<username>[^/.] )/?\\.(?P<format>[a-z0-9] )/?$', '(?P<version>(v1))/users/(?P<username>[^/.] )/?$']
Can someone guide me, how can I allow such username for url patterns with routers registered?
Thanks in Advance
CodePudding user response:
As you see, the default regex for URL values excludes .
:
/users/(?P<username>[^/.] )/
^
You will have to change that regex; if you're using viewsets, that's as easy as:
class UserViewSet(ModelViewSet):
lookup_value_regex = '[^/] '