Reputation: 26668
I am generating a uuid value and want to receive it from url in django, but the regex i am writing is not working and telling me page not found
import uuid
id = uuid.uuid4().hex
print id
be00e546822945bbb193b4ed80149c35
urlpatterns = [
url(r'^users/(?P<user_id>[0-9a-f]{32}\Z)/$', UserDetails.as_view(), name = 'users_detail'),
]
"GET /users/be00e546822945bbb193b4ed80149c35/ HTTP/1.1" 404 3302
So what would be the correct regex for uuid hex value in urls.py ?
Upvotes: 4
Views: 6190
Reputation: 105
urlpatterns = [
url(r'^users/(?P<user_id>[^/]+)/$', UserDetails.as_view(), name = 'users_detail'),
]
Upvotes: -1
Reputation: 4606
If you want to really check that you have UUID, try this one:
[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}
I've found it a while ago on SO and used it for a while to check that data is actually regexp. Haven't used it Django URLS directly, but I think it should be fine.
Upvotes: 4