52π
β
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.
π€Alasdair
78π
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)
]
π€vishes_shell
- [Django]-How to Lazy Load a model in a managers to stop circular imports?
- [Django]-Pass request context to serializer from Viewset in Django Rest Framework
- [Django]-How to put comments in Django templates?
6π
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.
π€Afshin Mehrabani
- [Django]-Why is using thread locals in Django bad?
- [Django]-ValueError: Missing staticfiles manifest entry for 'favicon.ico'
- [Django]-Django removing object from ManyToMany relationship
1π
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)
π€Geo Jacob
- [Django]-Get last record in a queryset
- [Django]-How to render Django form errors not in a UL?
- [Django]-Trying to trace a circular import error in Django
0π
had the same problem,
fixed it with this :
url(r'^offer_details/(?P<uuid>[0-9a-f\-]{32,})$', offer_details, name='offer_details')
`
π€lansanalsm
- [Django]-Django β Get the set of objects from Many To One relationship
- [Django]-AngularJS with Django β Conflicting template tags
- [Django]-Does SQLAlchemy have an equivalent of Django's get_or_create?
Source:stackexchange.com