Just like the numbers 0-9, uuid can also contain the numbers af and hyphens, so you can change the pattern to
(?P<factory_id>[0-9a-f-]+)
You may have a more strict regular expression, but it is usually not worth it. In your opinion, 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 are not in the database.
source
share