Reputation: 11523
I've been working with this url for username regex in Django for a while:
url(r'^.../(?P<username>[-\w]+)/$'
But now, I've got a strange case, sometimes Google answers with a username like this:
luke.skywalker
instead of lukeskywalker
And it looks like my regex doesn't accept dots - I get a NoReverseMatch
error. Could someone please help me with a correct regex?
Upvotes: 1
Views: 3813
Reputation: 662
Simply add lookup_value_regex
to your ViewSet:
class UserViewSet(viewsets.ModelViewSet):
lookup_value_regex = r"[\w.]+"
Upvotes: 2
Reputation: 599470
You can just add the characters you want to accept inside the square brackets:
r'^.../(?P<username>[-\w.]+)/$'
Upvotes: 8