Django urls uuid not working
As well as the digits 0-9, the uuid can also include digits a-f and hyphens, so you could should change the pattern to
(?P<factory_id>[0-9a-f-]+)
You could have a more strict regex, but it's not usually worth it. In your view you can do something like:
try:
factory = get_object_or_404(Factory, id=factory_id)
except ValueError:
raise Http404
which will handle invalid uuids or uuids that do not exist in the database.
Since Django 2.0 you don't even need to worry about regex for UUID and int with new Django feature: Path Converters.
Make code elegant again:
from django.urls import path
...
urlpatterns = [
...
path('getbyempid/<int:emp_id>/<uuid:factory_id>', views.empdetails)
]
Your url patterns is taking only numbers, try this one:
url(r'^getbyempid/(?P<emp_id>[0-9a-z-]+)/(?P<factory_id>[0-9a-z-]+)$',views.empdetails)
Just to complete other answers, please note that the Regex should be a-f
not a-z
, so:
urlpatterns = [
url(r'^request/(?P<form_id>[0-9A-Fa-f-]+)', views.request_proxy)
]
something like above could be the most accurate answer.