I've been trying to GET on generics RetrieveAPIView class using the re_path method in urls.py file. After trying several combinations, I can only get the path method to work. I would like to get an endpoint something similar to /file?id={some_uid}.
So far I have the following:
- django: 3.0.6
- djangorestframework=3.11.0
views.py:
class UploadFileInfoView(generics.RetrieveAPIView):
lookup_field = "id"
queryset = Upload.objects.all()
serializer_class = UploadModelSerializer
urls.py:
from django.urls import path, re_path
from . import views
urlpatterns = [
path("file/", views.UploadFileView.as_view(), name="UploadFile"),
# this works
# path("file/<uuid:id>", views.UploadFileInfoView.as_view(), name="UploadFileInfo"),
# this does not
re_path(r"^file/(?P<id>[0-9A-Fa-f-]+)", views.UploadFileInfoView.as_view(), name="UploadFileInfo"),
]
Have not used url method as the documentation says
This function is an alias to
django.urls.re_path(). It’s likely to be deprecated in a future release.