hebius
hebius

Reputation: 133

Django REST framework - endpoint for username

In my application users names can contain chars like :

. @ - _

I want to make an API endpoint api/users/{username} but it's impossible with these chars in URL. How to bite this kind of problem?

Upvotes: 0

Views: 76

Answers (1)

DevilPinky
DevilPinky

Reputation: 558

You need to use URL encoding for that and decode it in your view.

So "Username. @ - _" will be encoded as "Username.+%40+-+_".

To decode you can use urllib.unquote(url).decode('utf8').

Upvotes: 2

Related Questions